Woo Commerce提供code 要检查是否安装了WooCommerce,请执行以下操作:
/**
* Check if WooCommerce is active
**/
if ( in_array( \'woocommerce/woocommerce.php\', apply_filters( \'active_plugins\', get_option( \'active_plugins\' ) ) ) ) {
// Put your plugin code here
}
如果不知道WooCommerce安装在哪里,则:
$all_plugins = get_plugins();
$active_plugins = get_option( "active_plugins" );
foreach ( $all_plugins as $plugin_path => $value ) {
if( basename( $plugin_path, ".php" ) == \'woocommerce\') {
if( in_array( $plugin_path, $active_plugins ) ) {
return true;
}else {
return false;
}
}
}