Ecommerce Shopify WordPress Discussion

Shopify cart – limit for gift/free shipping currency issue

I have this shopify store (dawn 12) and I'm using the native currency selector. I have a custom cart setup where I did a progress bar and amount limit for a free gift to automatically be added after the set amount is surpassed. Nevertheless, I have an issue with the currency selector as the limit is not being converted along with the prices and therefore the value changes. In the attached image you'll see my cart with a limit supposed to be 900 DKK, which is now 900 euros after I changed the currency. I've tried to pull the rate of the selected currency without luck like this: const conversionRate = window.Shopify.currency.active === "DKK" ? 1 : window.Shopify.currency.rate; And also like this with liquid: {% assign convertedGiftLimit = gift_limit | times: cart.currency.rate %} Then I contacted Shopify's support which informed me it was not possible to fetch a currency rate for the selected currency at all. I thought that was quite weird but then tried to avoid it with the use of state.cart.original_total_price; instead which was supposed to return the cart value in the stores base currency. Also without any luck. All payments are drawn in the same currency (DKK) at check out btw. So now I'm not sure how to process, I hope I've just missed the obvious and some clever mind can point out what I'm doing wrong since this shouldn't be such a hassle I believe. You can see my code below. Thanks a million for helping me out! CONDITIONS FROM CART SECTION {% if hasGift %} // On load, we need to listen for whenever a customer removes a gift product, and then toggle our global state to prevent re-adding. const initRemoveGiftButtons = () => { const removeGiftButtons = document.querySelectorAll('.peech-cart-drawer-remove-gift'); for(const button of removeGiftButtons){ button.addEventListener('click', () => { window.cartHasRemovedGift = true; window.sessionStorage.setItem('cartHasRemovedGift', 'true') }) } } document.addEventListener('DOMContentLoaded', () => { initRemoveGiftButtons(); }) subscribeToCartStateUpdate(state => { const promoVariant = {{ gift_product_variant_id }}; const promoSubtotal = {{ section.settings.gift_limit }}; // If cart state exists and there is no Ajax Cart API request in progress if (state.status.cartStateSet && !state.status.requestInProgress) { // Add event-listener to support removing initRemoveGiftButtons(); let currentSubtotal = state.cart.original_total_price; // Find out if there is a product that was automatically added before const autoAddedLineItem = state.cart.items.findIndex( lineItem => { return lineItem.properties?._autoadded === 'Yes' ; }); // If there is the automaticaly added product — // lets calculate the currentSubtotal without the product if ( autoAddedLineItem > -1 ) { currentSubtotal -= state.cart.items[autoAddedLineItem].final_line_price; } const hasPromoItem = state.cart.items.filter((item) => item.variant_id == promoVariant); // Check if we've previously removed the gift. const hasRemovedGift = window.sessionStorage.getItem('cartHasRemovedGift') === 'true' || window.cartHasRemovedGift; // Check if cart contains a product found in the exclusion list. const excludedProductList = {{ section.settings.excluded_product_list | json }}; // Build two arrays of product ID's for comparison const excludedProductIDs = excludedProductList.map(item => item.id) const cartIDs = state.cart.items?.map(item => item.product_id); // Check if any cart product id appears in excluded products const hasExcludedProduct = cartIDs.some(id => excludedProductIDs.includes(id)); if (currentSubtotal >= promoSubtotal) { if (hasPromoItem.length == 0 && !hasRemovedGift && !hasExcludedProduct) { cartRequestAdd({ items: [{ id: promoVariant, quantity: 1, properties: { "_autoadded": "Yes" } }] }); // Re-set state just in case window.cartHasRemovedGift = false; window.sessionStorage.setItem('cartHasRemovedGift', 'false') } if(hasPromoItem.length > 0 && hasExcludedProduct){ // User already has excluded product, it should be removed. cartRequestChange({ "line": autoAddedLineItem + 1, "quantity": 0 }); } } else { if (hasPromoItem.length > 0) { cartRequestChange({ "line": autoAddedLineItem + 1, "quantity": 0 }); } } } }); {% endif %} CONDITIONS FROM CART SNIPPET {% assign delivery_progress = cart.total_price | times: 1.0 | divided_by: delivery_limit | times: 1.0 | times: 100 | floor %} {% if delivery_progress >= 100 %} {% assign achieved_delivery = true %} {% endif %} {% if hasGift %} {% assign selectedCurrency = cart.currency.iso_code %} {% assign gift_limit = section.settings.gift_limit %} {% assign convertedGiftLimit = 0 %} {% if selectedCurrency == 'DKK' %} {% assign convertedGiftLimit = gift_limit %} {% else %} {% assign convertedGiftLimit = gift_limit | times: 1.0 | divided_by: cart.currency.rate %} {% endif %} {% assign gift_progress = cart.total_price | times: 1.0 | divided_by: convertedGiftLimit | times: 1.0 | times: 100 | floor %} {% if gift_progress >= 100 %} {% assign achieved_gift = true %} {% endif %} {% comment %} Check if cart items include excluded item, and if so, write text accordingly {% endcomment %} {% assign cartIds = cart.items | map: 'product_id' %} {% assign hasExcludedProduct = false %} {% for product in excluded_product_list %} {% if cartIds contains product.id %} {% assign hasExcludedProduct = true %} {% break %} {% endif %} {% endfor %} {% else %} {% assign gift_progress = delivery_progress %} {% endif %} <div class="peech-free-shipping"> {% if achieved_gift and hasExcludedProduct == false %} <p style="margin: 0.5rem; font-size: 1.4rem">{{ 'sections.cart.gifts.gift_achieved' | t }}</p> {% elsif achieved_delivery %} <p style="margin-bottom: 0.25rem; font-size: 1.4rem">{{ 'sections.cart.gifts.free_shipping_achieved' | t }}</p> {% if hasGift and hasExcludedProduct == false %} {% assign gift_remaining = gift_limit | minus: cart.total_price | money_with_currency %} <p style="margin-top: 0; font-size: 1.2rem">{{ 'sections.cart.gifts.gift_remaining_html' | t: gift_remaining: gift_remaining }}</p> {% endif %} {% else %} {% assign delivery_remaining = delivery_limit | minus: cart.total_price | money_with_currency %} <p style="font-size: 1.4rem; margin: 0.5rem 0;">{{ 'sections.cart.gifts.free_shipping_remaining_html' | t: delivery_remaining: delivery_remaining }}</p> {% endif %} {% if hasExcludedProduct %} <p style="margin-bottom: 0.25rem; font-size: 1rem"> {{ 'sections.cart.gifts.cart_includes_excluded_product' | t }}</p> {% endif %} <div style="margin: 0.5rem 0 1rem 0; width: 100%; background: rgba(0,0,0,0.1); height: 12px; overflow: hidden; border-radius: 999px"> <span class="free_shipping_progress" style="display: block; background: #487A53; height: 100%; width: {{ gift_progress }}%"></span> </div>
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.