In my custom plugin I need to catch every time an order status changes from wc_on_hold
to wc_completed
so I tried to write down:
function so_status_completed( $order_id, $old_status, $new_status ) {
// if user is active , then get order amount and do all other personal calculations
global $wpdb;
$order = wc_get_order( $order_id );
//$payment_method = $order->get_payment_method(); //returns payment method bacs,cheque,cod etc
$user_id = $order->get_user_id();
$total = $order->get_total();
$order_data = $order->get_data();
//$order_total = $order->get_formatted_order_total();
$order_total = $order->get_total();
echo '<script>console.log("Debug Objects: Check order_total ' . $order_total. '");</script>';
}
add_action('woocommerce_order_payment_status_changed','so_status_completed',10,1);
But when I tried to change an order test from suspended to completed, I couldn't get on Chrome's Console that echo giving me the order price.....maybe using add_action isn't the right way to put a listener to that event?
Plus, since I am just here, I am using $order-get_total() which I searched on the net about his functionality but no deep docs found so I want to ask you if that method is the right one to retrieve order amount without fee applied?
Thanks! Cheers!!!