Only allow sale of product if a specific product is being purchased.

New Member
1 0 0

Hi, I am trying to add a purchase restriction on a product, so you can only add it to your basket, if you already have a specific product in your basket.

We are basically selling beer growler fills with local delivery, but we don't want to allot customers to buy the empty growlers (they are in short supply at times), so they can only buy a growler if they already have a growler fill in their basket.
How is this done?

I guess we can set the price ridiculously high, and then make a promo that it gets 'cheaper' if you have the growler fill in your basket.
But is there a way where you can just prohibit customers from adding it in the basket in the first place?

0 Likes
Highlighted
Shopify Expert
61 2 8

You could add an if statement that checked first if this is the growler product and then if the growler fill product is already in the cart. This statement would control if the Add To Cart button would show or not:

{% assign canAdd = false %}
        
{% if product.title == "Growler" %}
	{% for item in cart.items %}
		{%if item.title contains "Growler Fill"%}
			{% assign canAdd = true %}
		{% endif %}
	{% endfor %}
		
	{% if canAdd == true%}
		<!--Add To Cart-->
	{% endif %}
	
{% else %}
	<!-- Not growler product so show Add To Cart button -->
{% endif %}

You'd probably also want to add some code for your cart to remove the growler if the customer removes the growler fill product

0 Likes