Skip to main content
In this tutorial, we’ll walk through the process of converting a shopping cart into an order using the WooCommerce REST API. This is particularly useful when you need to programmatically create orders from cart sessions.
CoCart will provide it’s own checkout API in the future that will stream line the process. In the mean time, this is the best method.
You will need WooCommerce API credentials (consumer key and secret) for this.

Step 1: Retrieve the Cart Data

First, we’ll fetch the current cart data using the CoCart API:
In the following request examples, you would replace <cart_key>, <username> and <password> before sending the request.

Step 2: Prepare Order Data

Next, we’ll prepare the order data using the cart information. We’ll need to:
  1. Decode the cart JSON
  2. Set up billing and shipping information
  3. Configure payment details

Step 3: Add Shipping Method

If shipping is selected in the cart, we’ll add it to the order:

Step 4: Process Line Items

We’ll convert cart items into order line items:

Step 5: Create the Order

Finally, we’ll send the prepared data to the WooCommerce API to create the order:

Conclusion

You’ve now successfully converted a CoCart cart into a WooCommerce order! The response will contain the newly created order details. Remember to:
  • Replace example-store.com with your actual domain
  • Insert your WooCommerce API credentials
  • Handle any potential errors in the response
  • Consider adding error checking and validation
For more information about the available order parameters, consult the WooCommerce REST API documentation.