Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce - Call custom function after payment is completed

I am using Woocommerce for some project and i need to send the order id to some remote site when the payment is made. I am not finding the accurate hook to do this. Can anyone help me to find what's the correct hook to perform certain action after order is completed.

Here is what i have tried

add_action( 'woocommerce_thankyou', 'woo_remote_order' );

function woo_remote_order( $order_id ) {

// Lets grab the order
$order = new WC_Order( $order_id );


//Some action to make sure its working.

wp_mail( '[email protected]',' Woocommmerce Order ID is '.$order_id , 'Woocommerce order' );

}

Not sure which is the proper hook to perform this action. I am using paypal payment gateway for payment and orders successfully passes through.

like image 944
Nirmal Ram Avatar asked Feb 14 '23 06:02

Nirmal Ram


1 Answers

looks like you need add accepted_args on last parameters, Try this :

add_action( 'woocommerce_thankyou', 'your_func', 10, 1 );

function your_func($order_id) {

    $order = new WC_Order( $order_id );
    /* Do Something with order ID */
}
like image 170
Lafif Astahdziq Avatar answered Feb 15 '23 21:02

Lafif Astahdziq