• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Hook woocommerce_checkout_order_processed not firing and change status in custom plugin

julanjubalam

Well-known member
Trusted Uploader
Mar 3, 2019
266
401
63
I have tried changing my_status in my_cart_custom_table table in my custom plugin.

So I'm trying to create a plugin to send messages when a customer leaves their item in the cart. When this is done, my_status will be "1" in my_cart_custom_table
As long as the value in my_status is "1", messages will continue to be sent to customer phone number.

However when the customer continues their abandoned cart by placing an order (Pay Now in Checkout Page), my_status should change to "2".
But I have no more idea what's wrong with my code.
What I want is to change the value of my_status from 1 to 2, when the customer places an order (presses the "Pay Now" button) on the checkout page.

Here's my code :
Code:
private function define_public_hooks() {

  $this->loader->add_action( 'woocommerce_checkout_order_processed', $plugin_public,'my_change_order_status_place_order' , 999, 4);
}



public function my_change_order_status_place_order($order_id, $posted_data, $order){

        global $wpdb;
        $check = true;
        $table_name = $wpdb->prefix . 'my_cart_custom_table';
        if (is_a($order, 'WC_Order_Refund')) {
            $check = false;
        }

        if ($check) {
            $billing_phone  = $order->get_billing_phone();
            $customernumber = preg_replace('/[^0-9]/', '', $billing_phone);
            $country_code = $order->get_billing_country();
        $check_abandoned_entry_sql = $wpdb->prepare("SELECT id, my_customer_id FROM $table_name WHERE my_customer_mobile_no LIKE '$customernumber' AND my_status IN (0,1)");


            $matching_results = $wpdb->get_results($check_abandoned_entry_sql);
    
            if (is_array($matching_results) && COUNT($matching_results) > 0) {
                foreach ($matching_results as $result) {
                    $customer_id = $result->my_customer_id;
                    $wpdb->update($table_name, array("my_status" => 2), array('my_customer_id' => $customer_id));
                }
            }
        }
    
    }

It does not change the value "1" in my_status to "2" when the customer places an order on the checkout page.

I have also tried to follow some of the discussions here:

Anyone who answers or can help me find the problem here would greatly appreciate your help.

Thanks
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock