• Resolved sueh27

    (@sueh27)


    Can I pull the additional fields added by Checkout Manager and send with webhook using woocommerce_order_status_completed? How?

    I have added the following to the functions.php file to pull and send fields (just the email and product name at the moment). I need to include the two custom fields myfield13 and myfield 14 also.

    add_action( ‘woocommerce_order_status_completed’, ‘my_function’ );
    /*
    * Do something after WooCommerce set an order status as completed
    */
    function my_function($order_id) {

    // order object (optional but handy)
    $order = new WC_Order( $order_id );
    $billingEmail = $order->billing_email;
    $products = $order->get_items();

    foreach($products as $prod){
    $items[$prod[‘product_id’]] = $prod[‘name’];
    }

    $url = ‘https://requestb.in/15k6boy1’;

    // do some stuff here

    wp_remote_post( $url, array(
    ‘method’ => ‘POST’,
    ‘timeout’ => 45,
    ‘redirection’ => 5,
    ‘httpversion’ => ‘1.0’,
    ‘blocking’ => true,
    ‘headers’ => array(),
    ‘body’ => array( ‘billingemail’ => $billingEmail, ‘items’ => $items ),
    ‘cookies’ => array()
    )
    );
    }

    • This topic was modified 7 years, 7 months ago by sueh27.
  • The topic ‘Sending additional fields in webhook from Checkout Manager’ is closed to new replies.