Hope for your help!
I added this “purchase” button, but now it is shown also when the product is sold out. Can someone help me fix this ? I want it to be hidden when the product is not available, but for some reason I can either have both buttons shown or both hidden ![]()
Here is the website I’m working on & the liquid:
https://woollenandkind.com/collections/sold-rugs/products/persian-6-6-x-3-4
{%- form ‘product’, product, id: form_id, class: ‘product-single__form’ -%}
{%- if cart.taxes_included or shop.shipping_policy.body != blank -%}
{%- liquid
assign gift_card_recipient_feature_active = false
if block.settings.show_gift_card_recipient and product.gift_card?
assign gift_card_recipient_feature_active = true
endif
assign enable_dynamic_buttons = false
if show_dynamic_checkout and template != ‘product.preorder’ and gift_card_recipient_feature_active == false
assign enable_dynamic_buttons = true
endif
-%}
{%- if gift_card_recipient_feature_active -%}
{%- render ‘gift-card-recipient-form’, product: product, form: form, section: section -%}
{%- endif -%}
{%- if enable_dynamic_buttons -%}
{%- liquid
assign default_text = ‘products.product.add_to_cart’ | t
assign button_text = ‘products.product.add_to_cart’ | t
if template contains ‘preorder’
assign default_text = ‘products.product.preorder’ | t
assign button_text = ‘products.product.preorder’ | t
endif
unless current_variant.available
assign button_text = ‘products.product.sold_out’ | t
endunless
-%}
{%- if enable_dynamic_buttons -%}
Purchase
<button
{% if product.empty? %}type=“button”{% else %}type=“submit”{% endif %}
name=“add”
data-add-to-cart
class=“btn btn–full add-to-cart{% if enable_dynamic_buttons and product.selling_plan_groups == empty %} btn–secondary{% endif %}”
{% unless current_variant.available %} disabled=“disabled”{% endunless %}>
{{ button_text }}
{%- endif -%}
{%- if enable_dynamic_buttons -%}