Referencing product Metadata using JavaScript

Referencing product Metadata using JavaScript

mattgenefaas
Tourist
10 0 1

Any tips on referencing a product's metadata with JavaScript? I am trying to set customer limits to only order the Minimum Quantity defined in the product Metadata. I have been successful with all the liquid pages, just not pages where it is using JS which is the collection page. 

 

Using the Trade Theme 15.0 with Bulk option on the collection page.

 

Please help!

Reply 1 (1)

ProtoMan44
Shopify Partner
704 57 112

@mattgenefaas  

{% if product.metafields.custom_fields.minimum_quantity %}
  <script>
    var minQuantity = {{ product.metafields.custom_fields.minimum_quantity | json }};
  </script>
{% endif %}
 <script>
function handleQuantityChange() {
  var quantityInput = document.getElementById('quantityInput');
  var currentQuantity = parseInt(quantityInput.value, 10);
  if (minQuantity) {
    if (currentQuantity < minQuantity) {
      quantityInput.value = minQuantity;
    }
  }
}
 </script>
- A thirsty developer passionate about supporting the community. If you'd like to, you can  

Buy me a Coffee.


- Your Shopify Solution Specialist Get a Quote at

ProtoMan44

 - 

Chat On Whatsapp


Crafting exceptional e-commerce experiences to elevate your online presence. Let's build your success story together!