Using custom metafields to mark products as out of stock

Using custom metafields to mark products as out of stock

dankron
Shopify Partner
24 1 9

I'm trying to make a quick cheat code to mark porducts as out of stock  on my store, even tho when they are in stock on the system.

I've created the "True or False" variante metafield: variant.metafields.custom.sold_out

 

And i'm trying to use the following code:

 

{%- 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 and current_variant.metafield.custom.sold_out != 'true'
assign button_text = 'products.product.sold_out' | t
endunless
-%}

<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 and current_variant.metafields.custom.sold_out != 'true' %} disabled="disabled" {% endunless %}>
<span data-add-to-cart-text data-default-text="{{ default_text }}">
{{ button_text }}
</span>
</button>

 

But that doesn't seem to work, can anyone help me with this?

Replies 4 (4)

CustomService
Shopify Partner
10 0 0
current_variant.metafields.custom.sold_out != true
  • Change the condition, drop the quotes and try it out

 

dankron
Shopify Partner
24 1 9

nah same thing, no results...

CustomService
Shopify Partner
10 0 0
{{current_variant.available}}  {{current_variant.metafields.custom.sold_out}} 

 It is recommended to print the above conditions for judgment

dankron
Shopify Partner
24 1 9

It is printing "true or false" on both. That is not the issue.