Check if WooCommerce plugin is installed and activated on server (multisite and single installation)

/**
 * is_woocommerce_active - Check if WooCommerce is active.
 *
 * @return  bool
 */
function is_woocommerce_active() {
	$active_plugins = ( is_multisite() ) ?
		array_keys( get_site_option( 'active_sitewide_plugins', array() ) ) :
		apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) );
	foreach ( $active_plugins as $active_plugin ) {
		$active_plugin = explode( '/', $active_plugin );
		if ( isset( $active_plugin[1] ) && 'woocommerce.php' === $active_plugin[1] ) {
			return true;
		}
	}
	return false;
}

No comments yet.

Leave a Reply