Change Add to Cart to Choose Option for variant product in collection page

cs73
New Member
6 0 0

I have managed to add an Add to Cart button to my collection page in the Flex theme from Out of the Sandbox. However, for variant products, when you click on the Add to Cart, it automatically adds the default variant product to the Cart. I would like to change this so that instead of "Add to Cart" it displays "Choose Option" on the button and when clicked it takes you to the product page, where you then have to select the variant before adding this to the cart. 

My code for the Add to Cart button is:

<form method="post" action="/cart/add">
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
<input type="submit" value="{% if product.variants.first.available%}Add to Basket{% else %}Out of Stock{% endif%}" class="button ajax-submit action_button button--add-to-cart" {% unless product.variants.first.available %}disabled{% endunless %} />
</form>

Can anyone help with this?

0 Likes

You have an issue with your code where you have put hidden id with a value of the product.variant.first.id
You need to update it.
Please contact me to know how to fix this.

Founder of Shopify agency - Accomplishify.com
Contact me on: Michal.morek@accomplishify.com
0 Likes
cs73
New Member
6 0 0

What difference will this to the different buttons displaying?

0 Likes

The button will not have any issue with it.
The main thing is which variant id you are adding to the cart.
Here is your code you have one static id which is passed to cart so it will only add it,
The user will not have any choice in it.
So you need some dropdown thing.

Founder of Shopify agency - Accomplishify.com
Contact me on: Michal.morek@accomplishify.com
0 Likes
cs73
New Member
6 0 0

Thanks for your feedback.

I don't really want a dropdown there as some of the products have 20+ variants. I just want the Add to Cart button to become a Choose Option button instead, which then takes them to the product page. In the product page we have colour swatches enabled which show all the different shades, so they can choose the one they want from there.

Thanks.

0 Likes

This one is also simple. You just need to make the add to cart button an anchor link and need to remove the form code.

Founder of Shopify agency - Accomplishify.com
Contact me on: Michal.morek@accomplishify.com
0 Likes