Query discount applied from URL in liquid

I am directing prospects to my site using a URL like:

https://www.mysite.com/discount/64ME6K.

What object do I need to query in liquid to see if that discount will be applied at checkout? cart.discount_applications seems to be empty.

More detail:
I’d like to display a banner throughout the prospect’s visit letting them know that they’ll receive the discount when they order. So I’m trying to modify announcement-bar.liquid to detect if the discount code is active. As a test, I’ve tried:

{% for discount_application in cart.discount_applications %}
   <div><p>{{ discount_application.title }}</p></div>
{% endfor %}

That should show me all discounts that have been applied and are active, but I get no output.

I’ve also tried adding something to the cart, going to the checkout screen, and then returning to the homepage. The discount does appear in the checkout, so it does appear to be applied eventually. But if I cancel the checkout and go back to the homepage, I still don’t get the titles of any discounts that have been applied.

So I guess cart.discount_application isn’t the right object to query for a discount activated from a URL. What is?

Thanks for any help!
Lee

I am not an expert in this area, but what I am seeing is this information is not available on pages besides cart and checkout.

Source: https://community.shopify.com/c/shopify-design/check-if-discount-code-is-present/td-p/433593
https://community.shopify.com/topic/1649579

Thanks for replying quickly. That first post is from 2017 so I guess I’m hoping that -something- has changed since then! The second is a lot more recent, which is discouraging, but I hope someone else has some additional insight or ideas!

If you have coding experience, you could try using the AJAX API: https://shopify.dev/api/ajax

I looked at the AJAX Cart API reference. It does appear that if there’s something already in the cart I can probably get the line item discount for that item. But if the prospect has just arrived at the site so the cart is empty, it doesn’t appear that the cart API is going to return any info about a global discount. Is there something I’m missing?

Did you ever figure this out?