Different 'Add to Cart' text depending on product tag, inventory level and policy

New Member
2 0 0

Hello,

 

I have been working on this for a while but cant get it to work.

 

Basically our store has a lot of special order products that we order in from suppliers, and I want our Add to Cart button to reflect this by saying 'Special Order' instead of BUY NOW. Also we do pre orders, and use a tag to mark a preorder item, so would also like to have the button say Pre Order in that situation. Along with he standard Buy NOW if instock and Sold Out if inventory policy is set to deny:

 

I've tried this code and several variations so far:

		<button
			class="product-form--atc-button {% unless selected_variant.available %}disabled{% endunless %}"
			type="submit"
			{% unless selected_variant.available %}disabled{% endunless %}
			data-product-atc>
			<span class="atc-button--text">
              {% assign InvQuantity = selected_variant.inventory_quantity %}
            {% for tag in product.tags %}
              {% if product.tags contains 'pre_order' %}
              {{ 'product.buttons.pre_order' | t }}
              {% endif %}
              {% endfor %}
				{% if InvQuantity <= 0 and variant.inventory_policy == continue %}
					{{ 'product.buttons.special_order' | t }}
              {% endif %}
              {% if InvQuantity >= 1 %}
              {{ 'product.buttons.add_to_cart' | t }}
              {% endif %}
				{% if InvQuantity <= 0 and variant.inventory_policy == deny %}
					{{ 'product.buttons.sold_out' | t }}
				{% endif %}
			</span>
			<span class="atc-button--icon">
				{%- include 'icon-spinner' -%}
			</span>
		</button>
	</div>
</form>

I can get some of it to work and other parts not.

 

URL is alansbmx.com using Pixel Union Empire theme.

 

Any help is appreciated, I've tried many different ways but still nothing works.

 

Thanks, T

0 Likes