Using the Debut theme…
We added code to show a checkbox for the customer to agree to special terms if a certain product is added to the cart.
It is pretty simple. It looks to see if the item is in the cart, and shows the text and box if it is.
It works perfectly EXCEPT if the customer removes the item from the cart. The cart shows the item as removed, but the checkbox and accompanying text is still shown- until the page is refreshed.
I looked at various examples here, but have not found anything that helped so far.
Any suggestions would be most appreciated!
Hello @CRagsdell ,
They are different ways to do it.
One of the simple a/to he logic you are using is:
When certain product is in cart assign a specific class to its quantity selector and delete (x) button (icon)
Now first with JS check the action if quantity clicked and reach to ‘0’ uncheck the checkbox and hide the text.
secondly same with JS check the action when delete (x) icon clicked uncheck the checkbox and hide the text.
Thanks
I’ll try to clarify the request.
We need to completely remove the checkbox and text that is shown if the item is no longer in the cart. When we remove the item from the cart, the page shows the checkbox and text until there is a refresh. We need to completely remove the checkbox and text, not just de-select the checkbox.
Here is the code we use to determine if the item is in the cart.
{% for item in cart.items %}
{%- if item.title contains “BBQ” -%}
{%- increment is_bbq -%}
{% else %}
{%- increment not_bbq -%}
{%- endif -%}
{% endfor %}
We then check to see if we need to show the checkbox:
{%- if is_bbq > 1 -%}
By checking this box you understand and agree the following conditions: In order to protect our staff, guests and patients, we will be requiring all attendees to be vaccinated. We will be requiring proof of vaccination at the ticket booths the day of the event. All children under 12 need to wear masks as they are currently unable to be vaccinated. Please do not purchase a ticket if you are not vaccinated as you will not be allowed into the event and there will be no ticket refunds.
I agree with the terms and conditions.
{%- endif -%}
Seems like the easiest solution is to force a page refresh if they remove the item from the cart.
If you have a code example that would do that or a better way, I’d appreciate it.
I am fairly new to Liquid and sadly need more help than “Just do this…” advice.
Thanks!
Force refresh sounds easy but in this way you will ruined the theme default functionality.
And in the my last reply if you have doubt with term ‘uncheck’ and ‘hide’ no issue. There is alternate availed in JS which is know as remove function you can use it.
And if you are still looking for sample to force refresh check other free themes where on change of quantity and delete page gets refresh.
Thanks for the reply.
Sorry, but I can’t change the theme.
How can a forced page refresh “ruin” a theme?