Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Disable Line Item Discount Script if Discount Code Is Used

Disable Line Item Discount Script if Discount Code Is Used

SinkusStudio
Visitor
1 0 0

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?


Replies 2 (2)

magecomp
Shopify Partner
450 31 47

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.

 

Helping voluntarily. Please like and accept the solution if it helps. Thanks!
Our Bestseller Shopify Apps    |      Mobile App Builder by MageComp    |      Shoplock Hide Pages/Collections

Need a developer?  Just visit MageComp website

NomtechSolution
Astronaut
1245 113 154

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 }}

 

  1. You can comment out or remove this line of code to disable the Shopify discount script.

  2. 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 %}

 

  1. 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.

  2. 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.