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

How to remove the Swatches on certain page

Brain Shi

Hi,

I have a question when doing customize  on my templates.

On my site I check “Show swatches on archive / shop page” to display swatches on all the archive pages. That works fine! And I guess it uses hook something like “woocommerce_after_shop_loop_item” to add the swatches items.

My question is:
how do I remove the swatches on certain archive page? Actually there are more pages display the product loops other than the archive pages. I did a lot coding work to make some static pages also display the product loops. The swatches are displaying on all these places.

How do I “temporarily” hide the swatches on certain page? Can I do something like remove a hook on certain page to achieve this?

I’m a web developer. So please can you reply me some PHP or Javascript code for reference? I will understand.

Thank you very much!

Hakik Zaman

Hi Brain,

Thanks for getting back to us. Please try the following snippet using the Code Snippets plugin or, the child theme’s functions.php file:

add_filter('disable_woo_variation_swatches_archive_product', function($default, $product){
$target = [18]; //Insert the desired category term IDs inside the target. For Example: [14,45]
if( is_tax( 'product_cat', $target ) ){
return $default;
}
return true;
}, 10, 2);

Note: Please read the comment inside the code block carefully.

Thank You

Brain Shi

Yes that’s what I’m looking for. Works perfectly. Thanks!