I am trying to add a shipping message on the Shopify Cart Page. But would like to show a different message if a item in the cart is for a subscription. But am unsure on how to do this, as I can not seem to find a attribute for if a item is on subscription or not.
Below is my current code, I would be looking to do something like {% if subscription value > 0 } for example.
Thank you for your patience while we got back to you.
According to the Liquid objects reference doc, you can figure out if the cart contains any subscription products by inspecting cart.items.selling_plan_application. This object will only be set for subscription products, and will give you access to a couple of prices that will let you calculate the total subscription value of the cart.
That is very helpfully thanks. I have changed {% if shipping_value_left > 0 %} to {% if shipping_value_left > 0 or selling_plan_allocation.price < 19 %} however it dose not seem to be working, Is there anything I am missing? Full code below.
How are you retrieving selling_plan_allocation? In the code provided it’s used without being declared, but this isn’t a global variable like cart. It’s set on every line_item object found in the cart.items array. You’re probably looking at an iteration tag to calculate the total price of subscription products:
{% assign subscription_total = 0 %}
{% for line_item in cart.items %}
{% if line_item.selling_plan_allocation %}
{% subscription_total += line_item.selling_plan_allocation.price %}
{% endif %}
{% endfor %}
Ok thanks that makes sense, didn’t realize it needed declared.
I have added the code you wrote but it is saying unknown tag error (I have attached a screenshot) not sure why as it looks like it should be a known tag from line 22?
Thanks for the help, sorry If I am missing something simple.