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

Can I use variation swatches on some products only

Jo Holtom

Hi I’ve just bought this plugin but only want to use it on some products where the variables are colour-related. How do we switch off for some products? Or is this not possible? Many thanks

Jo

Hakik Zaman

Hi Jo,

Unfortunately, the feature is not currently available. You can disable swatch for a specific product (for archive/shop page) by adding the following snippet-

add_filter('wvs_pro_show_archive_variation_template', function($default){
   global $product;
   if( is_shop() && $product->get_id() == 13 ){ //13 is the product ID change is as you want
      return false;
   }
   return $default;
});

​But it’s a great idea. I’ll discuss this feature with my team.

In the meantime, please send the feature request here: https://storepress.fider.io/
and ask your other to upvote it.

Cheers!

Jo Holtom

Hi

 

Thanks for your help.

We added your code below to child theme > functions.php using a valid product ID (replacing 13) but it did not work. Is this correct?

 

add_filter(‘wvs_pro_show_archive_variation_template’, function($default){
global $product;
if( is_shop() && $product->get_id() == 13 ){ //13 is the product ID change is as you want
return false;
}
return $default;
});

 

==

Hakik Zaman

Hi Jo,

Do you want to disable swatches on the archive page or a single product page?

Yes, the above code is right. I have tested it on my end and got the result as expected.

Thank You

Jo Holtom

Thanks Hakik

We’d like to disable on specific single product pages. Should we be adding your code to the child theme functions.php file?

Kind regards

Jo

Hakik Zaman

Hi Jo,

Thanks for the clarification. Please check this screencast.

Here is the snippet-
add_filter( 'default_wvs_variation_attribute_options_html', function ( $default ) {
if ( is_product() && get_the_ID() == 15 ) { //here 15 is Product ID.
return true;
}
return $default;
} );

Thank You

Jo Holtom

Thank you. We have got the function working for a single product. Please advise how we would apply the same for multiple products.

Hakik Zaman

Hi Jo,

Please try the below snippet and remove the previous snippet. Also carefully follow the comments inside the snippet.

add_filter( 'default_wvs_variation_attribute_options_html', function ( $default ) {
if ( is_product() ) {

// Add the product IDs inside target array. For example 59,13. Note: add a comma after each product ID but not for the last one.

$target = [59,13];

   if(in_array( get_the_ID(), $target) ){
         return true;
   }
   return $default;
}
} );

Thank You