Skip to content

Add a product to the cart automatically if another "specific" product is added? #38

Discussion options

You must be logged in to vote

Hey!
In the code below I assume that you use product forms for "add to cart" functionality and they work via Liquid Ajax Cart. (If another script is responsible for adding a product to cart my code will not work).
Also I assume that you need to add only one scoop per cart, no matter how many protein packages are added.
To diffirentiate a protein product from other products I suggest you to add a property for all the protein product forms:

{% form 'product', product %}
  <!-- ... -->
  <input type="hidden" name="properties[_protein]" value="Yes">
  <!-- ... -->
{% endform %}

The script below will wait for a product with the _protein === Yes property

import { subscribeToCartAjaxRequests, ca…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@roarschouten
Comment options

@roarschouten
Comment options

@EvgeniyMukhamedjanov
Comment options

Answer selected by roarschouten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants