1
votes

I am implementing an integration using woocommerce. I would like to send the purchase made by the user to other system after the payment of the billet or credit card is confirmed. Does anyone know where I can get this return of the payment and how do I get the purchase's transaction ID?

I tried the code below, but the function doesn't seem to have been called;

add_action( 'woocommerce_payment_complete','send_payed_order_to_omie');
function send_payed_order_to_omie($order_id)
{
  /*Código que envia a venda para o ERP*/
}
1
Was does mean payment by billet?LoicTheAztec

1 Answers

2
votes

This is the correct hook for payed orders (excluding "bacs" (bank wire) and "cheque" payments that requires to be manually complete when payment is received).

You can see that in the source code of WC_Order payment_complete() method (used by all payment methods), where woocommerce_payment_complete hook is located, that set the transaction ID (when it's returned by the payment gateway).

To get the transaction ID you can use the WC_Order get_transaction_id() method.

So your code will be:

add_action( 'woocommerce_payment_complete','send_payed_order_to_omie');
function send_payed_order_to_omie( $order_id ) {
    $order = wc_get_order( $order_id );

    $transaction_id = $order->get_transaction_id();

    // Your other code
}

Code goes in functions.php file of the active child theme (or active theme). It should work.