Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Minimum 4 (quantity) with tag: “ MIN4 “

Solved

Minimum 4 (quantity) with tag: “ MIN4 “

sao
Explorer
237 0 22

Hi, I wanna create a tag “ MIN4 “ , when i put this tag to a product you will be forced to buy at least 4 pcs instead of at least one. Can someone please help me code this thing? 
website: www.aiciavem.ro

Accepted Solution (1)

swym
Trailblazer
157 33 73

This is an accepted solution.

Hey @sao

 

The minimum quantity rule that you are trying to set for the store can be split into two scenarios: 

 

1. Same minimum product limit for all products: If you want to set the same limit for all products in the store, you can do this by using a constant number directly. If you prefer to make it dynamic, use the theme customization settings to manage the value.

 

2. Setting up different minimum quantities at the product level: If you prefer to control the minimum quantity values at the product level, then using metafields would be a better approach. Please follow the steps to get an idea of how you can implement this: 
a. Setup product meatfields. Refer: https://help.shopify.com/en/manual/custom-data/metafields/using-metafields 

swym_0-1716357194006.png

 

b. On the product level update the minimum quantities for each product.

swym_1-1716357258505.png

 

Another approach is to use tags, which I guess you want to go with. Here’s how you can implement this:

a. Choose a proper tag name with a prefix or suffix, as per your convenience. Ex: MIN_4, MIN4 or 4_MIN

b. Add the tags to the products. 

c. To get the value saved in the tags, loop through the product tags and split the tag based on the prefix or suffix you added. Below is an example of how to fetch the minimum quantity value saved in a tag with the prefix "MIN":

{% comment %} Code for using tag-based approach. We are here using a demo tag with prefix of "MIN" {% endcomment %}
  
{% for tag in product.tags %}

    {% if tag contains 'MIN' %}

      {% assign minQty = tag | split: 'MIN' | last %}

      {% break %}

    {% endif %}
  
{% endfor %}

 

Once you are done fetching the minimum quantity that you want to set up on the store be it at the global level or the product level, follow these steps to implement the minimum quantity rules in your theme:

 

1. Using the minimum quantity fetched from above, you need to determine all the places in your store where customers can add products to the cart or update the cart item quantities. In your case, it will be the product page, collection page product grids, homepage product grids,  ajax cart,  cart popup, and the cart page itself. 

2. You need to update the minimum quantity everywhere possible using liquid or javascript.

 

Please note the code and file structure varies from theme to theme, so I won't be able to help you with the exact code. To achieve this you need to have a good command over Shopify liquid code, javascript, and even your store's theme file structure and code. If you are not familiar with the code, consider hiring a Shopify developer who can help you implement this feature.

 

Hope this helps! 

 

Regards, 

Abhishek from Swym

- Appreciate the assistance. Show your approval with a Like! And when your question finds its answer, seal the deal by marking it as an Accepted Solution!
- Our Solutions: Wishlist Plus | Swym Back in Stock Alerts | Swym Gift Lists and Registries

View solution in original post

Replies 4 (4)

Sweet_Savior_3
Shopify Partner
1361 104 144

Hello @sao 

 

Welcome to Shopify Community. 

 

This will need custom code setup including changes in liquid and JS. The code cannot be shared as there are a lot of tweaks to made in the theme. 

 

Thanks 

Don't forget to like and accept the solution to help others store owners.
Looking for an expert or Have any queries ? Send query to the Inbox
Coffee Tip ? Pay to shopify.dev.34@gmail.com
From Less To Further !!!

swym
Trailblazer
157 33 73

This is an accepted solution.

Hey @sao

 

The minimum quantity rule that you are trying to set for the store can be split into two scenarios: 

 

1. Same minimum product limit for all products: If you want to set the same limit for all products in the store, you can do this by using a constant number directly. If you prefer to make it dynamic, use the theme customization settings to manage the value.

 

2. Setting up different minimum quantities at the product level: If you prefer to control the minimum quantity values at the product level, then using metafields would be a better approach. Please follow the steps to get an idea of how you can implement this: 
a. Setup product meatfields. Refer: https://help.shopify.com/en/manual/custom-data/metafields/using-metafields 

swym_0-1716357194006.png

 

b. On the product level update the minimum quantities for each product.

swym_1-1716357258505.png

 

Another approach is to use tags, which I guess you want to go with. Here’s how you can implement this:

a. Choose a proper tag name with a prefix or suffix, as per your convenience. Ex: MIN_4, MIN4 or 4_MIN

b. Add the tags to the products. 

c. To get the value saved in the tags, loop through the product tags and split the tag based on the prefix or suffix you added. Below is an example of how to fetch the minimum quantity value saved in a tag with the prefix "MIN":

{% comment %} Code for using tag-based approach. We are here using a demo tag with prefix of "MIN" {% endcomment %}
  
{% for tag in product.tags %}

    {% if tag contains 'MIN' %}

      {% assign minQty = tag | split: 'MIN' | last %}

      {% break %}

    {% endif %}
  
{% endfor %}

 

Once you are done fetching the minimum quantity that you want to set up on the store be it at the global level or the product level, follow these steps to implement the minimum quantity rules in your theme:

 

1. Using the minimum quantity fetched from above, you need to determine all the places in your store where customers can add products to the cart or update the cart item quantities. In your case, it will be the product page, collection page product grids, homepage product grids,  ajax cart,  cart popup, and the cart page itself. 

2. You need to update the minimum quantity everywhere possible using liquid or javascript.

 

Please note the code and file structure varies from theme to theme, so I won't be able to help you with the exact code. To achieve this you need to have a good command over Shopify liquid code, javascript, and even your store's theme file structure and code. If you are not familiar with the code, consider hiring a Shopify developer who can help you implement this feature.

 

Hope this helps! 

 

Regards, 

Abhishek from Swym

- Appreciate the assistance. Show your approval with a Like! And when your question finds its answer, seal the deal by marking it as an Accepted Solution!
- Our Solutions: Wishlist Plus | Swym Back in Stock Alerts | Swym Gift Lists and Registries
sao
Explorer
237 0 22

Swym, I tried to make it work with metafields but I do not get it why is not working 😒😖 Please help me to make it work

ab89a221-a577-473b-bbc6-e9a74ba873ce.jpeg

kaalTechGeeks
Shopify Partner
318 58 78

Hey @sao

setting up the metafields was just one part of the task. The next task includes to use this metafield value to set the validation everywhere on the store from wherever a product can be added to the cart. 
in your store it is product page, homepage grids, collection page grids, ajax cart popup and the cart page. 
you need to add the validation everywhere possible. 

I know this is going to be a tough task, but that’s the only way to achieve this feature. Also also to implement it you need to have good knowledge for Javascript and Shopify liquid as well. 

Hope this gives you more insights. 

Thanks, 

KaalTechGeeks

- If my answers saved you time and headaches, consider buying me a coffee!
- Check my profile: KaalTechGeeks | Reach out to me on my socials - Instagram | Skype | Mail
- Was my reply helpful? Click Like to let me know! & if your question was answered, Mark it as an Accepted Solution!