• I have created an action to send data after an order is completed in WooCommerce. I have added the following code to the functionc.php file. I works, but the raw data is showing as: billingemail=sub%40imedi.co.za&items%5B90%5D=14-day+Free+Trial and I need it as a json array.

    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()
    )
    );
    }

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    'body' => json_encode( array( 'billingemail' => $billingEmail, 'items' => $items )),

    Next time you post code please use backticks or the code button. Failure to do so makes copy/pasting any part of your code difficult because all the quotes are wrong ??

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Webhook results not in array’ is closed to new replies.