Check if Certain Discounts Have Been Applied at Checkout

abelvf
New Member
5 0 0

I'm trying to create a Script in Checkout.liquid file that checks if a certain coupon was added to the checkout then hide the coupon code section so customers can't remove the checkout code. The script is not working so any assistance will be much appreciated. Thanks!

 

{% for item in checkout.line_items %}
	{% if discount_application.title == 'my_discount_code' %}
		<style>
        .tags-list {
    		    display: none;
        }

        .order-summary__section.order-summary__section--discount {
    		     display: none;
        }
		</style>  
	{% endif %}
{% endfor %}

 

 

0 Likes
Imtryin
New Member
2 0 0

@abelvf Any luck figuring this out? I too am try to check if certain discounts use entered. 

0 Likes
ryan99
Shopify Partner
6 0 2

As far as I can tell discounts activated by a code don't show up on the cart prior to the checkout page. I've checked both cart.json and all the liquid objects but no code-based discounts show in either, even if the code has been applied prior to checkout. Scripts and Automatic discounts work as expected.

I haven't found any documentation on why this may be or if there are conditions that affect how code-based discounts show. If anybody has any further insight let me know seems like a big miss from the shopify side.

0 Likes
StephanBayless
New Member
1 0 0

I don't know if you're still trying to figure this out, but I solved it while trying to get a line-item discount.

Here I did it for item.discounts;

{% for discount in item.discounts %}      
     {% if discount.code contains '[discount code title here]' %}

          some code here

    {% endif %}
{% endfor %}

 

But you could wrap that in a cart.items for loop;

{% for item in cart.items %}
    {% for discount in item.discounts %}
        {% if discount.code contains '[discount title here]' %}

            some code here

        {% endif %}
    {% endfor %}
{% endfor %}

Hope it works as well for you as it did for me.

Shopify Hacker. Message me if you want to break your Shopify store and stop paying for Apps.
0 Likes