fbpx
Want To Add Extra Images Per Product Variation For Free? Download Now

Hide variation swatch when only one

Odd request, but I have several products with only one variation. I’d like to hide the swatch entirely when there is only one available. Any suggestion? I see where I could make the change in the frontend.js, but am hoping you have a snippet or might offer an alternative. Thanks in advance!

Here are two links to my test site with an example…

https://copy.holycityfarms.com/product-category/flower/

https://copy.holycityfarms.com/product/blitzed-dry-sift-puck-4-grams/

 

Hakik Zaman

Hi Shawn,

Thanks for reaching out to us. Please try the below snippet and follow the instruction inside the code block:

add_filter('default_woo_variation_swatches_single_product_dropdown_html', function($default){
$target = [14]; //Insert the product id’s inside the target. For Example: [14,45]
if( in_array( get_the_ID(), $target ) ){
return true;
}
return $default;
}, 10, 1);

Thank You

That turned it back into a dropdown on the product page and didn’t seem to impact the archive/products page. Any other possible solutions?

Hakik Zaman

Hi Shawn,

Do you want to display a dropdown on the archive page too? If so, please also add the following:

add_filter('disable_woo_variation_swatches_archive_product', function($default, $product){
$target = [14]; //Insert the product id’s inside the target. For Example: [14,45]
if( in_array( $product->get_ID(), $target ) ){
return true;
}
return $default;
}, 10, 2);

Thank You

No, I am just trying to hide the controls entirely…no swatches or dropdowns. The scenario is just one variation on a product in the archive grid. I’d like to set the display to none for any products with only one variation…

Hakik Zaman

Hi Shawn,

Unfortunately, the feature is not currently available.

​But it’s a great idea. Please send the feature request here: https://storepress.fider.io/

and ask your other to upvote it.

Cheers!