Change Add to Cart text only for products with a certain tag

Solved

Change Add to Cart text only for products with a certain tag

EmeraldService
Visitor
2 0 1

Hi all,

 

I need to modify the Add to Cart button text to show "Place Special Order" when an item has SpecialOrder:Y as a product tag. I see in the product-info.liquid file there is this line of code:

{%- else -%}
<button type="submit" class="product-form__add-button button button--primary" data-action="add-to-cart">{{ 'product.form.add_to_cart' | t }}</button>
{%- endif -%}

However, I can't find what to edit to change the Add to Cart button text or if this is even the correct line to edit.

 

I'm thinking I can add an if statement like so, so that only items with that tag get changed:

{%- if product.tags contains 'SpecialOrder:Y' -%}

I'm not sure of the best place to put it, and what exactly would go in it. Any help would be appreciated. Currently using the theme warehouse.

 

Accepted Solution (1)

JoesIdeas
Shopify Partner
2500 229 673

This is an accepted solution.

If that code above is for the add to cart button, then I would just copy that same format.

 

{% if product.tags contains "SpecialOrder" %}
  <button type="submit" class="product-form__add-button button button--primary" data-action="add-to-cart">Special text to show on ATC button</button>
{% else %}
  <button type="submit" class="product-form__add-button button button--primary" data-action="add-to-cart">{{ 'product.form.add_to_cart' | t }}</button>
{% end %}

 

 

To test this, duplicate your live theme then make the edits in the new theme.

 

Usually this would be found in a file like product-info.liquid, product-form.liquid, etc. If you can't find it, start with the product.liquid template and read the code to see each of the snippets that are added, then open those files and look for add to cart code.

• Creator of Order Automator [auto tag, fulfill, connect FBA, daily jobs]
• Co-Creator of Product Automator [suite of features for products / collections]
• Shopify developer for 10+ years, store owner for 7 years
• Blog: Shopify Tips, Guides, and Automation Tactics

View solution in original post

Replies 4 (4)

JoesIdeas
Shopify Partner
2500 229 673

This is an accepted solution.

If that code above is for the add to cart button, then I would just copy that same format.

 

{% if product.tags contains "SpecialOrder" %}
  <button type="submit" class="product-form__add-button button button--primary" data-action="add-to-cart">Special text to show on ATC button</button>
{% else %}
  <button type="submit" class="product-form__add-button button button--primary" data-action="add-to-cart">{{ 'product.form.add_to_cart' | t }}</button>
{% end %}

 

 

To test this, duplicate your live theme then make the edits in the new theme.

 

Usually this would be found in a file like product-info.liquid, product-form.liquid, etc. If you can't find it, start with the product.liquid template and read the code to see each of the snippets that are added, then open those files and look for add to cart code.

• Creator of Order Automator [auto tag, fulfill, connect FBA, daily jobs]
• Co-Creator of Product Automator [suite of features for products / collections]
• Shopify developer for 10+ years, store owner for 7 years
• Blog: Shopify Tips, Guides, and Automation Tactics
EmeraldService
Visitor
2 0 1

Worked perfectly, I just added an else if statement with this line and all is good. 

{% elsif product.tags contains 'SpecialOrder:Y' %}
   <button type="submit" class="product-form__add-button button button--primary" data-action="add-to-cart">Place Special Order</button>

 Thank you for the assistance!

JoesIdeas
Shopify Partner
2500 229 673

Woohooo!

• Creator of Order Automator [auto tag, fulfill, connect FBA, daily jobs]
• Co-Creator of Product Automator [suite of features for products / collections]
• Shopify developer for 10+ years, store owner for 7 years
• Blog: Shopify Tips, Guides, and Automation Tactics
SweatStrategies
Visitor
1 0 0

Hey, this is super nice and works for me too on Dawn! However, if I change to another variant of the product it changes back to Add to cart - any idea how to prevent this from happening?