Support » Plugin: WooCommerce » [Plugin: WooCommerce – excelling eCommerce] Order ID for Payment Notification to External Webservice

  • Resolved mwklein


    I am using the woocommerce_payment_complete hook as the trigger to notify a 3rd party webservice of receipt of payment. I need to send a number of details related to the order in the notification including the Order ID. Unfortunately, I have not been able to find the Order object in scope.

    function woocommerce_payment_complete_custom_action() {
    	global $woocommerce;
    	//Get all the user information from the checkout object
    	$checkout =& $woocommerce->checkout->posted;
    	$donor_first_name = $checkout['billing_first_name'];
    	//Get all the product and contribution information from the cart (cart is cleared
    	//immediately after this code is executed)
    	$cart =& $woocommerce->cart;
    	//Iterate through all the products in the cart and get the item details
    	foreach ($cart->cart_contents as &$item) {
    		$product_id = $item['product_id'];
    	//How do I get the order ID associated with this completed payment?
    	//Additional code here to send to webserivce
    add_action('woocommerce_payment_complete', 'woocommerce_payment_complete_custom_action');

    Any ideas how I can get the order ID? Or preferably the order object?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The ‘woocommerce_payment_complete’ action passes the id of the order as an argument. So if you start supporting the argument, you can easily create an object out of it:

    function woocommerce_payment_complete_custom_action( $order_id ) {


    add_action( 'woocommerce_payment_complete', 'woocommerce_payment_complete_custom_action', 10, 1 );

    The $order_id variable can be used to create an Order object, just like this:

    $order_object = new WC_Order( $order_id );

    Thanks Coen! Super simple fix… I didn’t realize the order ID is passed.

    Hi mwklein and Coen,

    I’m wondering if you can point me in the right direction here.

    I have set up a WordPress site with WooCommerce installed, using Paypal as the only payment gateway. I am new to WooCommerce and can work my way around code changes but am no programmer as such.

    There site will use a 3rd party logistics company to dispatch the orders once placed. They have given me a “URL to use to receive IPN posts” which I entered on the Paypal side.

    Test orders get to Paypal OK but they aren’t being forwarded to the 3rd party. It appears as though the IPN returns to the website itself somehow.

    Is there somewhere in the WooCommerce code that I can manually set the IPN URL so that the 3rd party receives the order once payment is complete?

    Many thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: WooCommerce – excelling eCommerce] Order ID for Payment Notification to External Webservice’ is closed to new replies.