Woocommerce place order using curl?

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

Related posts

Leave a Reply

1 comment

  1. 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.

    curl -X POST https://example.com/wc-api/v2/orders 
        -u consumer_key:consumer_secret 
        -H "Content-Type: application/json" 
        -d '{
      "order": {
        "payment_details": {
          "method_id": "bacs",
          "method_title": "Direct Bank Transfer",
          "paid": true
        },
        "billing_address": {
          "first_name": "John",
          "last_name": "Doe",
          "address_1": "969 Market",
          "address_2": "",
          "city": "San Francisco",
          "state": "CA",
          "postcode": "94103",
          "country": "US",
          "email": "john.doe@example.com",
          "phone": "(555) 555-5555"
        },
        "shipping_address": {
          "first_name": "John",
          "last_name": "Doe",
          "address_1": "969 Market",
          "address_2": "",
          "city": "San Francisco",
          "state": "CA",
          "postcode": "94103",
          "country": "US"
        },
        "customer_id": 2,
        "line_items": [
          {
            "product_id": 546,
            "quantity": 2
          },
          {
            "product_id": 613,
            "quantity": 1,
            "variations": {
              "pa_color": "Black"
            }
          }
        ],
        "shipping_lines": [
          {
            "method_id": "flat_rate",
            "method_title": "Flat Rate",
            "total": 10
          }
        ]
      }
    }'