• Resolved codrx

    (@codrx)


    Hello,
    We are having a strange issue with WooCommerce which is deactivate randomly. We don’t know why, we don’t receive any error, nothing.
    We are using this code to try to debug but we receive notification every time we access plugins page.
    Maybe it’s our code wrong, I don’t know but we are facing with this issue from 1 year almost, and the plugin deactivate it’s randomly, maybe 1 time per month. Lately it’s almost 2-3 times per week.
    We have tried to deactivate plugin one by one, but the issue persists, also, tried with storefront, same issue. We really don’t know what to do anymore.
    Also, if we put this code on a fresh WordPress installation we receive the notification.
    Do you have any ideas regarding this?
    Waiting for your reply,
    Thank you!

    function prevent_woocommerce_deactivation($actions, $plugin_file, $plugin_data, $context) {
        // Path to the WooCommerce main file.
        $plugin = 'woocommerce/woocommerce.php';
    
        // Check if the plugin is WooCommerce.
        if ($plugin_file == $plugin) {
            // Remove the Deactivate link.
            if (array_key_exists('deactivate', $actions)) {
                unset($actions['deactivate']);
    
                // Get current user.
                $current_user = wp_get_current_user();
    
                // Get request details.
                $ip_address = $_SERVER['REMOTE_ADDR'];
                $user_agent = $_SERVER['HTTP_USER_AGENT'];
                $request_url = $_SERVER['REQUEST_URI'];
    
                // Log the details.
                error_log("Attempted WooCommerce deactivation at " . date( 'Y-m-d H:i:s' ));
                error_log("Attempted by: " . $current_user->user_login . " (email: " . $current_user->user_email . ")");
                error_log("IP Address: " . $ip_address);
                error_log("User Agent: " . $user_agent);
                error_log("Request URL: " . $request_url);
    
                // Send an email.
                $to = 'emailaddress';
                $subject = 'Attempted WooCommerce Deactivation';
                $message = 'An attempt was made to deactivate WooCommerce at ' . date( 'Y-m-d H:i:s' );
                $message .= "\n\nAttempted by: " . $current_user->user_login . " (email: " . $current_user->user_email . ")";
                $message .= "\n\nIP Address: " . $ip_address;
                $message .= "\nUser Agent: " . $user_agent;
                $message .= "\nRequest URL: " . $request_url;
    
                wp_mail( $to, $subject, $message );
            }
        }
    
        return $actions;
    }
    
    add_filter('plugin_action_links', 'prevent_woocommerce_deactivation', 10, 4);
Viewing 3 replies - 1 through 3 (of 3 total)
  • Saif

    (@babylon1999)

    Hello @codrx,

    I can imagine how frustrating this must be for you. Could you possibly discuss the issue with your hosting provider?

    They might have a script or a global function that automatically disables plugins during updates, for example. Plus, you might find some helpful clues in the server error logs every time the plugin gets disabled.


    Let us know how it goes!

    Thread Starter codrx

    (@codrx)

    Hello,
    Thank you very much for your reply.
    Unfortunately I don’t think this is the issue, a script or a global function because we have other websites on the same hosting provider but we don’t have the same issue.
    Did you manage to check the function above? If it’s working correctly?
    Waiting for your reply,
    Thank you!

    Saif

    (@babylon1999)

    Thank you very much for your reply.
    Unfortunately I don’t think this is the issue, a script or a global function because we have other websites on the same hosting provider but we don’t have the same issue.

    That’s very unusual!

    As I understand, the plugin is deactivating silently without any errors, correct?

    The only thing I can think of is that something is changing the plugin folder name. If the plugin is deactivating due to an error, your admin email address should receive an email with some relevant error logs.

    You can also find a copy of the logs in WooCommerce > Status > Logs. Just look for ‘fatal’ in the drop-down menu. Can you think of anything that might be causing this behaviour?

    Did you manage to check the function above? If it’s working correctly?

    Custom solutions are not something we can assist with per our support policy as we are not developers. That said if you want to trigger an action when a plugin is deactivated you should use the register_deactivation_hook() function.

    However, that’s not a sustainable solution and since the cause is unknown, more things might break in the future.

    At the time being, please contact your hosting provider as I mentioned previously. Perhaps they can give you more insight or share server error logs of when this happened.

    Also, please attach your system status report here, maybe we can spot some clues from it. You can find it via WooCommerce > Status. Select “Get system report” and then “Copy for support” (after you scroll down a bit)”. Once done, please paste it here in your reply or via a text-sharing service like https://gist.github.com/


    Let us know how it goes!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘WooCommerce deactivate randomly’ is closed to new replies.