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

Read More
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( 'sagarseth9@example.com',' 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.

Related posts

Leave a Reply

3 comments

  1. 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 */
    }
    
  2. add_action( 'woocommerce_subscription_payment_complete', 'YourFunction', 1, 2);  
    function YourFunction ($order_id)
      {
      $order = new WC_Order( $order_id );
      wp_mail( 'sagarseth9@example.com',' Woocommmerce Order ID is '.$order_id , 'Woocommerce order' );
    
      }
    

    The add_action call must be placed at the very beginning of your plugin, if using wordpress, or if a theme, in functions.php.