Warm tip: This article is reproduced from stackoverflow.com, please click
javascript shopify

How to Remove Default Variant Option and Have Empty Radio Buttons

发布于 2020-04-22 11:18:07

I apologize in advance as I'm not able to get the minimal amount of code possible, but I'm currently working on a Shopify site (that I didn't build) and I want to have no default variants selected. For example, if you go to this page https://thriveworkwear.com/products/carpenter-work-pants-5300-pro, you'll see that the default options are Color: Hickory Waist:30W Inseam:30L.

Is there a way to disable the default variant functionality? Meaning that no variants are selected and the user has to select them manually.

I tried to follow this guide https://help.shopify.com/en/themes/customization/products/variants/how-to-add-a-pick-an-option-to-drop-downs and this one but they DIDN't work.

I have also tried adding this:

document.querySelector('input[name="name0"]:checked').checked = false;
document.querySelector('input[name="name1"]:checked').checked = false;
document.querySelector('input[name="name2"]:checked').checked = false;

to the theme.js file but it didn't work. It seems to work if I add it through the console tab but not when I add it on the site.

Any help is appreciated.

Questioner
Efrain Lemus
Viewed
20
drip 2020-02-09 01:49

It seems that the options are generated from the following APP: https://apps.shopify.com/best-custom-product-options

This means that everything is generated using Javascript that you may not have control over.

You will have to reveal the App if there is an option in it to disable the default selected options or if there is an event you can listen to when the App applies the options.

The final line is to use Mutation Observer and wait for HTML modifications in the form to fire your code, but this is the final approach if nothing else works.