De-activation of plugin dependant on another

I am writing a Woocommerce extension plugin and have managed to set it so Woocommerce must be installed and activated under the Wordpress admin pages.

If both Woocommerce and my extension plugin are activated and Woocommerce is de-activated, my plugin stays active.

How do I de-activate my plugin when Woocommerce is also de-activated?

Edit 1.

I have tried this, and other similar attempts. The hook is correct, but for some reason deactivate_plugins() does not deactivate the plugin that I am writing.

function custom_plugin() {

    if (is_plugin_active('custom_plugin/custom_plugin.php')){

register_deactivation_hook( 'woocommerce/woocommerce.php', 'custom_plugin');

1 answer

  • answered 2018-09-18 07:05 Kanewilliam

    Try this below code your active theme OR custom plugin.

    function custom_plugin_deactivation( $plugin, $data_value ) {
        if ($plugin=="custom/custom.php")
    add_action( 'deactivated_plugin', 'custom_plugin_deactivation', 10, 2 );