{"id":9021679,"date":"2017-04-12T06:23:26","date_gmt":"2017-04-12T06:23:26","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/custom-webhook-results-not-in-array\/"},"modified":"2017-04-12T06:23:26","modified_gmt":"2017-04-12T06:23:26","slug":"custom-webhook-results-not-in-array","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/custom-webhook-results-not-in-array\/","title":{"rendered":"Custom Webhook results not in array"},"content":{"rendered":"<p>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&amp;items%5B90%5D=14-day+Free+Trial and I need it as a json array.<\/p>\n<p>add_action( &#8216;woocommerce_order_status_completed&#8217;, &#8216;my_function&#8217; );<br \/>\n\/*<br \/>\n * Do something after WooCommerce set an order status as completed<br \/>\n *\/<br \/>\nfunction my_function($order_id) {<\/p>\n<p>\t\/\/ order object (optional but handy)<br \/>\n\t$order = new WC_Order( $order_id );<br \/>\n\t$billingEmail = $order-&gt;billing_email;<br \/>\n\t$products = $order-&gt;get_items();<\/p>\n<p>\tforeach($products as $prod){<br \/>\n\t  $items[$prod[&#8216;product_id&#8217;]] = $prod[&#8216;name&#8217;];<br \/>\n}<\/p>\n<p>\t$url = &#8216;http:\/\/requestb.in\/15k6boy1&#8217;;<\/p>\n<p>\t\/\/ do some stuff here<\/p>\n<p>wp_remote_post( $url, array(<br \/>\n &#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>\n &#8216;timeout&#8217; =&gt; 45,<br \/>\n &#8216;redirection&#8217; =&gt; 5,<br \/>\n &#8216;httpversion&#8217; =&gt; &#8216;1.0&#8217;,<br \/>\n &#8216;blocking&#8217; =&gt; true,<br \/>\n &#8216;headers&#8217; =&gt; array(),<br \/>\n &#8216;body&#8217; =&gt; array( &#8216;billingemail&#8217; =&gt; $billingEmail, &#8216;items&#8217; =&gt; $items ),<br \/>\n &#8216;cookies&#8217; =&gt; array()<br \/>\n)<br \/>\n );<br \/>\n}<\/p>\n","protected":false},"template":"","class_list":["post-9021679","topic","type-topic","status-publish","hentry","topic-tag-function-php","topic-tag-webhook"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9021679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9021679\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=9021679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}