How can I alter code for different button labels on my ecommerce site?

yesterday

Hi guys

I’m currently trying to figure out how to amend this code to suit the following purpose:

I sell both items and workshops. I would like the buttons for my items to be ‘add to cart’, and for my workshops to be ‘book now’.

I’ve made sure that all my items are tagged as specific products (eg, rings, earrings etc) and my workshops tagged as workshops.

Still, I’m unsure how to add a condition to the code that will amend the displayed buttons. Can anyone help?

Here is the current code:

<button type=“submit” name=“add”
{% unless current_variant.available %} aria-disabled=“true”{% endunless %}
aria-label=“{% unless current_variant.available %}{{ ‘products.product.sold_out’ | t }}{% else %}{{ ‘products.product.add_to_cart’ | t }}{% endunless %}”
class=“btn product-form__cart-submit{% if section.settings.enable_payment_button %} btn–secondary-accent{% endif %}”
data-add-to-cart>

{{ ‘Add to Cart’ | json | remove: ‘"’ }}

Thank you!

Nina

Hi @iasthai_og

You would need to add a tag conditional check before that cart button code as per the below:

{% if product.tags contains "ring" %}
Code for Ring Button
{%else%}
Code for other button
{%endif%}

Let me know if this makes sense!

1 Like

It does! I’ll give it a go. Thank you so much

Should that help answer your query, we always appreciate liking & marking an as answer to let the community find quality solutions faster. Thanks!

1 Like