Need Help Hiding Specific Product Variants Using Metafields

Full chat transcript below. All timestamps in UTC timezone.

01:22 System: An advisor has joined the chat

01:22 Mich Lim (Support Advisor): This is Mich from the Shopify Support Team. Thanks for reaching out! How are you doing today?

01:23 Matthew Youn: Hi Mich

01:23 Matthew Youn: I need you help with applying the changes required to hide specific variants from displaying on our online store

01:23 Matthew Youn: I know I need to create metafields but I need your assistance to apply it in the theme

01:23 Matthew Youn: Would you be so kind as to help me?

01:24 Mich Lim (Support Advisor): Hello, Matthew! I can see that you are requesting assistance regarding hiding specific variants from your online store. I can see that you need an extra hand in applying these metafields to your theme, and I’m here to provide you the support you need!

01:25 Matthew Youn: Thanks a lot

01:25 Matthew Youn: https://support.shopify.io/attachments/0199cbb9-7016-738f-b38e-98998bd0f9c5

01:26 Mich Lim (Support Advisor): While I’d love to apply direct changes to your theme, we do have limited permissions, especially since it directly affects your live store. However, I’m dedicated to providing you assistance today. To assist you more effectively, Matthew, I’ll ask you a few questions to have a better understanding of the request, and if necessary, we may need to check some aspects of your store together. Should we find this out of my scope of support, I’d be more than happy to refer you to our experts. To start, I just want to confirm if the store you’re pertaining to is 9f268d-7b.myshopify.com?

01:26 Matthew Youn: I created this but seems I’ll also need to apply the changes in the theme

01:26 Matthew Youn: Yes correct store

01:28 Matthew Youn: According to your resources, I just need to do the following which would be very easy for you: Modify the variant selection code to exclude or hide variants where the metafield custom.hide_variant equals 1.

01:28 Mich Lim (Support Advisor): Thank you so much for confirming the store, Matthew! From your screenshot, I can see that you’re already working on metafield variants, and only need assistance in adding it to your store, yes?

01:29 Matthew Youn: Yes, just need to apply this small code, it seems

01:32 Mich Lim (Support Advisor): I’m glad you reached out, Matthew. I appreciate that you’ve already done the hard work of setting up the metafields, and I understand you just need a hand applying the final changes to your theme.

I want to be completely transparent with you: as a Shopify Support advisor, I cannot directly edit your theme’s code or apply changes to your store on your behalf. This policy is in place for your store’s security and stability. Even a small change to a live theme can unintentionally cause unexpected issues for your customers.

The good news is that you’re very close to getting this done, and I can give you the best path forward to make that “small code” edit.

01:33 Matthew Youn: Thank you. Just to let you know, I have received assistance is some minor code changes from your support before

01:34 Matthew Youn: So I guess it wouldn’t actually be too difficult when you have my permission to apply the changes. For a safer route, we can first apply in an unpublished theme, and if it works, we can then apply in the live theme

01:38 Mich Lim (Support Advisor): Thank you for clarifying that, Matthew. I understand your logic completely, and I appreciate you suggesting a safer route with an unpublished theme.

While your approach is well-thought-out, as a Shopify Support Advisor, I cannot make any code changes to your store, even with your permission or in an unpublished theme. This is a strict policy that is in place for your store’s security and long-term stability.

While on occasion, an advisor may provide a small code snippet to help with a minor issue, that is not a standard practice and is generally outside our scope of support.

Even a minor code change can unintentionally cause a major issue later on, especially after a theme update or if it conflicts with an app. By avoiding these changes, we ensure that your store remains stable and secure for all of your customers.

01:38 Mich Lim (Support Advisor): To safely apply the change, you will need to get assistance from a developer. You have two great options!

Shopify Experts Marketplace: You can hire a vetted, professional Shopify Expert through our marketplace. They are experienced with these types of customizations and can ensure the changes are made without any issues.

Shopify Community Forums: You can post your question, along with a screenshot of the issue and the name of your theme, in the Shopify Community Forums. Often, other merchants or developers can provide quick code snippets to help you resolve this.

01:39 Mich Lim (Support Advisor): I’m here to assist you in getting this sorted out, but I’m unable to make changes to your store directly. Would you like me to guide you on how to hire a Shopify Expert or how to post in the Shopify Community Forums?

01:39 Matthew Youn: Not really helpful hiring an expert for a minor change which should be already a default feature

01:40 Matthew Youn: At least, please tell me via screenshot where to add the code and I’ll do it myself

01:46 Mich Lim (Support Advisor): I completely understand where you’re coming from, Matthew — that’s a very fair point. It does sound like a small change, and I agree it would be convenient if this were built in by default. While I’m unable to send screenshots or point to a specific line of code within your theme files (not because I don’t want to, but simply because I don’t have the resources, knowledge, nor training to effectively assist you on this request), I can help you post in our community forum instead. This way, our experts and other merchants can provide you more assistance. Does this work for you, Matthew?

01:46 Matthew Youn: OK

01:50 Mich Lim (Support Advisor): Thank you so much for your understanding, Matthew. Pulling up the Community page right now. Hang on please!

01:54 Mich Lim (Support Advisor): Hi, Matthew! Are we still connected?

01:54 Matthew Youn: yes

01:57 Mich Lim (Support Advisor): Thank you so much for staying with me here, Matthew! I’ve just drafted a message you can post to the Community Forum for assistance on your coding request. Our first step is to log into the forum. Then, click on New Topic, where a message field will open. Here’s what you can input here:

Title: Need Help Hiding Specific Product Variants Using Metafields

Hi everyone,

I’m hoping to get some guidance on a small theme customization I’m trying to implement.

I’ve created a metafield for product variants called custom.hide_variant, and my goal is to hide specific variants from displaying on the online store when that metafield equals 1.

I’m not sure where exactly in the code this condition should be added. Has anyone done something similar before? Where in the theme files (e.g., main-product.liquid, product-form.liquid, or section code) should this condition be placed?

Any best practices to ensure the hidden variants don’t appear in the dropdown or cause inventory/URL issues?

I’m comfortable editing the theme myself, so even general guidance or a code structure example would be really helpful.

Thanks so much in advance for your help!

— Hamid

Hey @hamid9,

Thanks for sharing this here. This requested changes requires to do the custom code in your theme file. By any chance can you share the store url and collab code.
Thanks

Thanks. Would you guide me as to where insert the code? If you could kindly share some instructions, it would be much appreciated. https://maisonkoko.com/