1

I'm trying to check if woo commerce plugin is active then add some options to the option panel. but this code doesn't work right.

can anyone tell me what is wrong? thanks.

 if( class_exists( 'WooCommerce' )) {//add options}
LoicTheAztec
  • 184,753
  • 20
  • 224
  • 275
IRDN
  • 87
  • 10

1 Answers1

1

Try the following instead:

if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
    // Yes, WooCommerce is enabled
} else {
    // WooCommerce is NOT enabled!
}
LoicTheAztec
  • 184,753
  • 20
  • 224
  • 275
  • thanks a lot it works. and could you please tell me why that code doesn't work? all developers I see use that and works truly. – IRDN Feb 25 '21 at 09:01
  • 1
    It depends of the context and where you are using the code… Also take care when you say *"All developers…"* as most of them are not really developers… – LoicTheAztec Feb 25 '21 at 10:35