I am getting a json formatted result of a Woocommerce order with jquery ajax.
j.ajax({
type: 'GET',
url: 'https://www.mywebsite.com/wp-json/wc/v2/orders/123456',
cache: false,
data: {
format: 'json'
},
headers: {
"Authorization": "Basic " + btoa("my_key" + ":" + "my_secret")
},
success: function(data) {
var result = JSON.parse(data);
//console.log(data);
console.log(result);
console.log(result[id]);
},
error: function(xhr,status,error) {
console.log(error);
},
complete: function() {
}
});
I am receiving an error above in console that says:
jqueryscript.js?ver=4.9.7:173 Uncaught ReferenceError: id is not defined at Object.success (jqueryscript.js?ver=4.9.7:173) at i (jquery.js?ver=1.12.4:2)
This is how the json looks like:
{
"id": 0003,
"parent_id": 0,
"number": "0003",
"order_key": "wc_order_dsadsa003",
"created_via": "checkout",
"version": "3.3.1",
"status": "processing",
"currency": "dollar",
"date_created": "2018-06-27T02:52:40",
"date_created_gmt": "2018-06-27T02:52:40",
"date_modified": "2018-06-27T02:52:41",
"date_modified_gmt": "2018-06-27T02:52:41",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "448.00",
"total_tax": "0.00",
"prices_include_tax": false,
"customer_id": 1,
"customer_ip_address": "127.0.0.1",
"customer_user_agent": "mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/67.0.3396.99 safari/537.36",
"customer_note": "",
"billing": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "adasd",
"address_2": "",
"city": "asdas",
"state": "",
"postcode": "8000",
"country": "",
"email": "johndoe@gmail.com",
"phone": "1213123"
},
Do you know how can I grab the field id that has a value of 0003 and address_1 with value of adasd?
I would want to put it to an html element. Any idea is appreciated. Thanks