Skip to content

Instantly share code, notes, and snippets.

@UVLabs
Last active October 27, 2021 16:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UVLabs/c9872b7797700e4d2deb0f414e403af6 to your computer and use it in GitHub Desktop.
Save UVLabs/c9872b7797700e4d2deb0f414e403af6 to your computer and use it in GitHub Desktop.
Check if WooCommerce is active on a website and output admin notice if not
<?php
// check if WooCommerce is activated
function tld_wc_check(){
if ( class_exists( 'woocommerce' ) ) {
global $tld_wc_active;
$tld_wc_active = 'yes';
} else {
global $tld_wc_active;
$tld_wc_active = 'no';
}
}
add_action( 'admin_init', 'tld_wc_check' );
// show admin notice if WooCommerce is not activated
function tld_wc_admin_notice(){
global $tld_wc_active;
if ( $tld_wc_active == 'no' ){
?>
<div class="notice notice-error is-dismissible">
<p>WooCommerce is not activated, please activate it to use <b>XXX Plugin</b></p>
</div>
<?php
}
}
add_action('admin_notices', 'tld_wc_admin_notice');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment