Last active
October 27, 2021 16:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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