I want to write a custom plugin that does some action after woocommerce order is completed, but I can\'t get this hook to work. I can see this question asked many times.
woocommerce_order_status_changed and woocommerce_order_status_completed actually work for me. After struggling for 2 days i realized that you just can't var_dump or var_export or print_r or whatever in the admin panel, it just won't work.
So if you are a newbie like me and thought those actions weren't working, just try triggering another action like sending a mail for example.
This code works:
function your_function( $order_id ){
$order = new WC_Order( $order_id );
$to_email = 'testing_mail@sample.com';
$payment = $order->get_payment_method_title();
$headers = 'From: Your Name ' . "\r\n";
wp_mail($to_email, 'subject', $payment, $headers );
}
add_action( 'woocommerce_order_status_completed', 'your_function');