- 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 :
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
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