To check if the WooCommerce plugin is active on your WordPress site, follow this simple PHP code snippet. It works for both single-site and multisite setups. This snippet checks whether WooCommerce is listed as an active plugin, ensuring that your eCommerce functionality is enabled.
Simply add this code to your theme’s functions.php file or a custom plugin. This method gives you quick and reliable results.
<?php
// Include the plugin.php file which provides functions for plugin management
require_once ABSPATH . 'wp-admin/includes/plugin.php';
// Get the list of active plugins for the current site
$blog_plugins = get_option( 'active_plugins', array() );
// If it's a multisite, get the active site-wide plugins
$site_plugins = is_multisite() ? (array) maybe_unserialize( get_site_option('active_sitewide_plugins' ) ) : array();
// Check if WooCommerce is active either as a regular plugin or as a site-wide plugin in a multisite setup
if ( in_array( 'woocommerce/woocommerce.php', $blog_plugins ) || isset( $site_plugins['woocommerce/woocommerce.php'] ) ) {
echo 'WooCommerce is active!';
} else {
echo 'WooCommerce is not active.';
}
?>