Hello,
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
https://wordpress.org/plugins/woo-variation-swatches/
https://wordpress.org/plugins/woo-thumbnails-slider/
This is website plugins are running one
https://brightledshoes.com/shop/low-top-womens-white/
Arnav Joy answers:
try this in functions.php
<?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.
https://pastebin.com/1wwxETJ1
Thanks
Arnav Joy comments:
try this
https://pastebin.com/sssB0TfX
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..
Thanks,
Have a great day!!!