2
votes

I'm using the WooCommerce REST API (http://woocommerce.github.io/woocommerce-rest-api-docs/#introduction) and have added a new field (shipping_phone) to the checkout page using their example here:

https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

This new field appears on the checkout page and I can populate this and it is saved to my order - here's how it appears in the WordPress admin page for an order:

enter image description here

I'm now trying to download the Order with the shipping_phone data by using this GET request:

/wp-json/wc/v1/orders/3454

but the shipping_phone field isn't included in the downloaded fields. Here's the Shipping fields from the GET response:

"shipping": {
"address_1": "45 Jones Road", 
"address_2": "", 
"city": "Bondi", 
"company": "BS Consulting Pty Ltd", 
"country": "AU", 
"first_name": "Betty", 
"last_name": "Sanders", 
"postcode": "2026", 
"state": "NSW"
}, 

It's also not located anywhere else in the JSON data. How do I do a GET request to get an Order which includes this new custom field?

1

1 Answers

0
votes

You can use the WooCommerce REST API v2 or later to get the Order Meta Data which includes these custom fields. If you GET an Order:

wp-json/wc/v3/orders/3454

it will include a meta_data array with these custom field values:

"meta_data" : 
[
    {
        "id" : 4672,
        "key" : "_shipping_method",
        "value" : [ "flat_rate:1" ]
    },
    {
        "id" : 4673,
        "key" : "_shipping_phone",
        "value" : "08 9632 7412"
    }
]