Hook woocommerce_checkout_order_processed not firing and change status in custom plugin

julanjubalam

Active member
Trusted Uploader
Mar 3, 2019
227
249
43
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
 

Latest posts

Forum statistics

Threads
69,228
Messages
908,447
Members
237,064
Latest member
MUSTAFA MERAJ

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu