I am trying to give a graceful custom message upon activation of the plugin, if Woocommerce is not activated.
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
The above express is to check whether Woocommerce is active and if it returns false, I do not want the plugin to be activated and wants to throw a custom error. I have tried to stop execution with die()
and trigger_error
. In these cases, it shows a FATAL ERROR
.
What I usually do is throw and admin notice if WooCommerce isn’t available. And then just stop the running of your plugin.
Any code that you put here at the end will be run as long as WooCommerce is active. Note, I didn’t test this so be careful of typos.
Have a look at
deactivate_plugins
function . Try this:Here my solution:
This way show message and you can enrich it like explain here and stop execution too.