0

So as the topic hints, I'm trying to get WooCommerce to accept my date_created that I'm sending along with the order I'm creating via REST:

POST https://www.example.com/wp-json/wc/v2/orders
{
   (order_fields)
   ...

   "date_created": "05-12-2017 13:00:00"
}

The field is readonly sadly, so does anyone know if this is possible?

The reason I need this, is the orders are created in an external system, and the dates need to be the same across both systems.

0

date_created is read-only value meaning that you cannot set it over the REST API. What you can do is:

  1. Send creation time from your "external system" as order meta data (sample PHP code below) and then in WooCommerce trigger the action using custom plug-in which updates order date_created according to a meta value.
$json_encode['meta_data'][0]['key'] = 'my_date_created';
$json_encode['meta_data'][0]['value'] = '05-12-2017 13:00:00';
  1. Update date_created in your "external system" with date_created from jSon returned by Woocommerce in order to have values synchronised.

If you just want to pair order records do it over order ID returned in jSon by Woocommerce (Woocommerce returns a jSon when the order was created successfully). You will add order ID record to your "external system".

1
  • 1
    I'll give you credit for the answer, as I ended up doing something similar.
    – DarkNeuron
    Dec 7 '17 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.