Adding add to cart button on grid view and using a different button for a specific collection

Solved
adrianaprinting
Tourist
9 1 0

Ok, sent you a dm!

0 Likes
JHKCreate
Shopify Partner
2537 417 603

I edited the code to reflect both or with both unless and if conditions but I still can't get it to connect to the contact page. - Did you create the Contact Us page? Seems it's not published yet.

Just realized that I also have a collection that has a mix of products with prices that needs the add to cart function and the contact us for pricing- Add a tag on those products: ContactUsForPricing and we will then update the if statement to switch between those two button options on the fly.

 

- Did we solve your issue? Like & Mark As Solution to help the community
- Should you need any direct help: contact@jhkcreate.com
- Learn more about us: jhkcreate.com

0 Likes
adrianaprinting
Tourist
9 1 0

Yup the page is published. You can open it from the navigation bar too.

Okay, will add the ContactUsForPricing tag.

0 Likes
adrianaprinting
Tourist
9 1 0

So I changed the code to point to the product tags instead:

{% unless product.tags contains 'ContactUsForPricing' %}
 <form align="center" method="post" action="/cart/add">
  <input type="hidden" name="id" value="{{ product.variants.first.id }}" />
  <input align="center" type="submit" value="{% if product.variants.first.available%}Add to cart
	{% else %}
	Sold Out
	{% endif%}" class="btn" 
	{% unless product.variants.first.available %}disabled{% endunless %} />
  <input type="hidden" name="return_to" value="back" />
</form>
{%endunless%}

{% if product.tags contains 'ContactUsForPricing' %}
 <form align="center" method="post" action="/pages/contact-us">
    <input align="center" type="submit" target="_blank" value="Contact us for pricing" class="btn"/>
  </form>
{%endif%}  

 

It works for all pages but I still could get the contact page to work

0 Likes
JHKCreate
Shopify Partner
2537 417 603

This is an accepted solution.

Switch the form element to a button element or wrap it with with an <a href="/pages/contact-us" >     </a>

It is being submitted when you're clicking on it hence the 404. If you refresh the 404 it asks you if you would like to resubmit your form, 

- Did we solve your issue? Like & Mark As Solution to help the community
- Should you need any direct help: contact@jhkcreate.com
- Learn more about us: jhkcreate.com

0 Likes
adrianaprinting
Tourist
9 1 0

This is an accepted solution.

what do you know? It finally worked. haha

Final code here:

    {% unless product.tags contains 'ContactUsForPricing' %}
 <form align="center" method="post" action="/cart/add">
  <input type="hidden" name="id" value="{{ product.variants.first.id }}" />
  <input align="center" type="submit" value="{% if product.variants.first.available%}Add to cart
	{% else %}
	Sold Out
	{% endif%}" class="btn" 
	{% unless product.variants.first.available %}disabled{% endunless %} />
  <input type="hidden" name="return_to" value="back" />
</form>
{%endunless%}

{% if product.tags contains 'ContactUsForPricing' %}
    <a class="btn" align="center" href="/pages/contact-us" target="_blank" value="Contact us for pricing">Contact us for pricing</a>
  </form>
{%endif%}  

 

Thank you so much for correcting my code! Now I feel silly for insisting on using form for it. 

0 Likes
JHKCreate
Shopify Partner
2537 417 603

Not to worry! You did quite a bit of the heavy lifting as well! Cheers!

- Did we solve your issue? Like & Mark As Solution to help the community
- Should you need any direct help: contact@jhkcreate.com
- Learn more about us: jhkcreate.com

0 Likes
jdariza
Tourist
9 0 2

Thanks, but I have a product with variants and it appears SOLD OUT, but not all of them are sold out. Did you fix it? 

0 Likes