0

I'm running into a problem with a custom function in a hook of WooCommerce orders status. All I need is to show the order id, a custom field and the items of the order in error_log

function mysite_woocommerce_order_complete( $order_id ) {

error_log( "Payment has been received for order $order_id" );

 $order = wc_get_order( $order_id );
 $user_acct = get_post_meta( $order_id, 'billing_acc', true );

    foreach ($order->get_items() as $item_id => $item_data) {

        $product = $item_data->get_product();
        $product_name = $product->get_name();
        $item_quantity = $item_data->get_quantity();

        error_log( "Product $product_name Quantity $item_quantity User $user_acct" );
        } 
}
add_action( 'woocommerce_order_status_completed', 'mysite_woocommerce_order_complete', 1, 1 );

This works perfectly when a customer complete payment and the product is virtual and downloadable, the order gets the status "Completed" and print what I need in error.log

[07-Jul-2020 20:18:53 UTC] Payment has been received for order 2846 [07-Jul-2020 20:18:53 UTC] Product Pacote Jered's 2 Quantity 2 User b1n

The problem is: My store accept a method of payment (bank transfer) and after the payment is verified by the admin, he needs to manually set the order as Completed. In this action the hook isn't called, I need it to run just like the other way. I've tried a lot of similar hooks, all ends with the same problem, it works if the order gets completed automatically but doesn't work if the order is completed manually.

  • [woocommerce_order_status_completed not triggered](https://stackoverflow.com/questions/36315825/woocommerce-order-status-completed-not-triggered) – 7uc1f3r Jul 07 '20 at 20:43
  • None of those replies solves the problem, those hooks aren't fired when changing manually the order to completed by admin – Fabio Angeluci Jul 08 '20 at 01:56

0 Answers0