Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Load plugin only on woocommerce product pages WordPress



I am using these two plugins below but would like them to run only on woocommerce product page. I would like to put code in my functions.php file to achieve this.

Here are the two plugins

This is website plugins are running one

Answers (3)


Arnav Joy answers:

try this in functions.php


add_filter( 'option_active_plugins', function( $plugins ){

$p1 = "woo-variation-swatches/woo-variation-swatches.php";

$p2 = "woo-thumbnails-slider/woo-thumbnails-slider.php"

if( !is_woocommerce() ){

$k1 = array_search( $p1, $plugins );
$k2 = array_search( $p2, $plugins );

unset( $plugins[$k1] );
unset( $plugins[$k2] );


return $plugins;

} );

George Sprouse comments:

Hi Arnav,

I have added code but it produced a critical error on website. Below is link to my functions.php file maybe you can tell me where to put it.


Arnav Joy comments:

try this

George Sprouse comments:

Hey Arnav,

Any other idea? it still produces error

Arnav Joy comments:

Can you send me succes to the site? In my email ?


Mohammed Remeez answers:

Hey George,
Just try with this filter hook,

add_filter( 'option_active_plugins', function( $plugins ){

//your plugin path
$wooVariationSwatchPlugin = "woo-variation-swatches/woo-variation-swatches.php";

$pluginIndex = array_search( $wooVariationSwatchPlugin, $plugins );

//check if not woocommerce page.
if( !is_woocommerce() ) {
unset( $plugins[$pluginIndex] );

return $plugins;

Make sure this function would load before loading other plugins, otherwise this will not work.
or you can add this code to any mu-plugins or add priority to the function such as -1, 1, etc..

Have a great day!!!


Gabriel Reguly answers:

Arnav answered it :-)