PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 11, 2022

[FIXED] Which WooCommerce hook or function that receives the payment response by billet and credit card?

 November 11, 2022     hook-woocommerce, payment-gateway, php, woocommerce, wordpress     No comments   

Issue

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*/
}

Solution

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.



Answered By - LoicTheAztec
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing