I need to place order using curl in wordpress woocommerce. i already tried this but its not working. My error
{"result":"failure","messages":" nttt
We were unable to process your order, please try again.</li>nt</ul>n","refresh":"true","reload":"false"}
My code is given below
$datas = "billing_country=IN&billing_first_name=renuka&billing_last_name=fg&billing_company=fsdfgdf&billing_address_1
=dsfdsfsd+fdfsdf&billing_address_2=fsdfsdfsdf&billing_city=madurai&billing_state=BR&billing_postcode
=6334535&billing_email=renuka%40osiztechnologies.com&billing_phone=2343546&shipping_country=IN&shipping_first_name
=renuka&shipping_last_name=fg&shipping_company=fsdfgdf&shipping_address_1=dsfdsfsd+fdfsdf&shipping_address_2
=fsdfsdfsdf&shipping_city=madurai&shipping_state=BR&shipping_postcode=6334535&order_comments=&shipping_method
%5B0%5D=free_shipping&payment_method=braintree&braintree-card-expiry-month=10&braintree-card-expiry-year
=2032&_wpnonce=a5dbf257ca&_wp_http_referer=%2Fprojects%2Ftutor%2Fwp-admin%2Fadmin-ajax.php";
$ch = curl_init('http://localhost/project/wp-admin/admin-ajax.php?action=woocommerce_checkout');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
Take a look at Create Order in the WooCommerce REST API version 2.
For the WooCommerce REST API to work, you have to have Permalinks properly enabled and you have to generate an API key with write permission for an admin user.
Using their example which I have included below, you should be able to create an order using curl. Note that this relies on HTTPS. If you use HTTP, then you’ll need to use OAuth1. See their OAuth1 explanation here.
I would highly recommend using the WooCommerce REST API client from Gerhard Potgieter, though you’ll have to modify it slightly to work with v2 instead of v1. And you’ll have to modify it to create an order rather than update.