I am using the Debut theme. I have two types of products, one with the tag ‘On sale’ and others with the tag ‘Normal’.
I want that if the customers add products with the tag ‘On sale’ checkout is disabled. If they add products with the tag ‘Normal’, or products with both tags, the checkout should proceed as normal.
The following code helps to eliminate checkout for ‘On sale’ items,
{% if product.tags contains ‘Normal’ %}
{% else %}
Not Available
{% endif %}
I tried to use operators (and, or) for including a scenario where checkout is possible with both tags but it isn’t working.
{% if product.tags contains ‘Normal’ or ‘On sale’ %}
{% else %}
Not Available
{% endif %}
The above won’t stop checkout if there’s only ‘On sale’ tag.
{% if product.tags contains ‘Normal’ and ‘On sale’ %}
{% else %}
Not Available
{% endif %}
The above won’t work because the tags are specific to one product and not both.
So when it comes to using ‘or’ and ‘and’ you have to do two full conditions, the way you have it set up is it only completes one condition but not the other (technically it does but not how your wanting to do it). So instead of
{% if product.tags contains 'Normal' and 'On sale' %}
You would do
```javascript
{% if product.tags contains 'Normal' and product.tags contains 'On sale' %}
Hope it helps.
Regards,
Martin
If this code is being added to the cart page do keep in mind that a customer can head straight to checkout by going to /checkout. This, along with accelerated gateways, might skip your cart based logic.
{% if item.product.tags contains 'Normal' and item.product.tags contains 'On sale' %}
it works
{% else %}
Not Available
{% endif %}
Also to go on what Jason said you could remove the buy now button so customers won’t bypass the cart page. It’s located in theme panel for the product page. Go to the Product pages section then untick show dynamic checkout button and save it.
I successfully made changes following your answer to stop customers from going directly to the checkout page. The other issue is still pending even after using item.product.tags
Let me add a brief explanation of the logic I want to apply,
Checkout conditions (Display ‘Checkout’ button on the Cart page)
If there is a ‘Normal’ product in the cart
If there are multiple products in the cart with at least one ‘Normal’ product
No Checkout condition (Display ‘Not Available’ text replacing Checkout button)
If there is only an ‘On Sale’ product in the cart
I hope it will make things clear and might help you in proposing another solution.
I’ll propose to you a partial solution but I’ll let you figure out on the rest of it. This solution does the first two for checkout conditions but if it doesn’t find it then it prints not available. Furthermore if it has the onsale tag it will not do anything. Your part will be to implement the no checkout condition with onsale tags.