woocommerce/docs/extension-development/check-if-woo-is-active.md

757 B

post_title menu_title tags
How to check if WooCommerce is active Check if WooCommerce is active how-to

You can wrap your plugin in a check to see if WooCommerce is installed:

// Test to see if WooCommerce is active (including network activated).

$plugin_path = trailingslashit( WP_PLUGIN_DIR ) . 'woocommerce/woocommerce.php';

if (

in_array( $plugin_path, wp_get_active_and_valid_plugins() )

|| in_array( $plugin_path, wp_get_active_network_plugins() )

) {

// Custom code here. WooCommerce is active, however it has not

// necessarily initialized (when that is important, consider

// using the \`woocommerce_init\` action).

}

Note that this check will fail if the WC plugin folder is named anything other than woocommerce.