Personalized checkout and custom promotions with Shopify Scripts
In our store we give a blanket 25%-off for customers that have an account with us. Sort of the Members-Club discount.
But we still want to use all the capabilities of the discount codes.
Is there a way to disable shopify discount script if the discount code is used?
Hello @SinkusStudio
Yes, it is possible to disable the Shopify discount script if a discount code is used. This can be done using a script that checks if a discount code has been applied, and if so, disables the store's automatic discount. Here's an example script:
// Check if a discount code has been applied
if (Shopify.checkout.discountApplied === true) {
// Disable the automatic discount
Shopify.CustomerAccounts.setAutomaticDiscount(false);
}
You can add this script to your theme's JavaScript file or create a new script in the Shopify Scripts Editor. Make sure to test the script thoroughly before deploying it to your store.
In our store we give a blanket 25%-off for customers that have an account with us. Sort of the Members-Club discount.
But we still want to use all the capabilities of the discount codes.
Is there a way to disable shopify discount script if the discount code is used?
{{ 'discount.js' | asset_url | script_tag }}
You can comment out or remove this line of code to disable the Shopify discount script.
Add a condition to enable discount script for specific codes: If you still want to use the discount script for specific discount codes, you can add a condition around the script code. For example:
{% if cart.discount_code and cart.discount_code.code != 'YOUR_DISCOUNT_CODE' %}
{{ 'discount.js' | asset_url | script_tag }}
{% endif %}
Replace 'YOUR_DISCOUNT_CODE'
with the actual discount code you want to exclude from disabling the script. This condition checks if a discount code is applied to the cart and ensures that the discount script is not loaded when the specific code is used.
Save and test: After making the necessary changes, save the cart.liquid
file and test the functionality on your store's cart page. Ensure that the discount script is disabled when the specified code is used, while still functioning for other codes.
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024