Reputation: 2653
I'm not so good in PHP because of the way it prints arrays. I return a var called $order, and I get the following:
{
"id":14770,
"parent_id":0,
"status":"on-hold",
"currency":"EUR",
"version":"3.0.7",
"prices_include_tax":true,
"date_created":{
"date":"2017-06-08 12:11:24.000000",
"timezone_type":1,
"timezone":"+00:00"
},
"date_modified":{
"date":"2017-06-08 12:11:24.000000",
"timezone_type":1,
"timezone":"+00:00"
},
"discount_total":"0",
"discount_tax":"0",
"shipping_total":"4.09",
"shipping_tax":"0.8589",
"cart_tax":"1.1107",
"total":"11.35",
"total_tax":"1.9696",
"customer_id":8,
"order_key":"wc_order_59393eec03f4a",
"payment_method":"bacs",
"payment_method_title":"Bankoverschrijving",
"transaction_id":"",
"customer_user_agent":"mozilla\/5.0 (windows nt 10.0; win64; x64) applewebkit\/537.36 (khtml, like gecko) chrome\/58.0.3029.110 safari\/537.36",
"created_via":"checkout",
"customer_note":"",
"date_completed":null,
"date_paid":null,
"cart_hash":"c517e3080e56d6d341bc93d4ff219b31",
"number":"14770",
"meta_data":[
{
"id":257891,
"key":"_wc_customer_order_xml_export_suite_is_exported",
"value":"0"
},
{
"id":257892,
"key":"_wc_customer_order_xml_export_suite_customer_is_exported",
"value":"0"
},
{
"id":257938,
"key":"_billing_email-2"
},
{
"id":257939,
"key":"vat_number",
"value":"NL234077232B02"
},
{
"id":257940,
"key":"_vat_country",
"value":"NL"
},
{
"id":257941,
"key":"_vat_number_validated",
"value":"valid"
},
{
"id":257942,
"key":"_customer_location_self_certified",
"value":"no"
},
{
"id":257943,
"key":"_eu_vat_data",
"value":{
"eu_vat_assistant_version":"1.7.8.170421",
"exchange_rates_provider_label":"BitPay",
"invoice_currency":"EUR",
"taxes":{
"25":{
"label":"21% NL BTW",
"vat_rate":"21.0000",
"country":"NL",
"tax_rate_class":"",
"tax_payable_to_country":"NL",
"amounts":{
"items_total":1.1107,
"shipping_total":0.8589
}
}
},
"vat_currency":"EUR",
"vat_currency_exchange_rate":1,
"vat_currency_exchange_rate_timestamp":1493135026
}
},
{
"id":257944,
"key":"_eu_vat_evidence",
"value":{
"eu_vat_assistant_version":"1.7.8.170421",
"location":{
"is_eu_country":1,
"billing_country":"NL",
"shipping_country":"NL",
"self_certified":"no"
},
"exemption":{
"vat_country":"NL",
"vat_number_validated":"valid"
}
}
},
{
"id":257947,
"key":"_wcpdf_proforma_date",
"value":"2017-06-08 14:11:25"
},
{
"id":257948,
"key":"_wcpdf_proforma_number",
"value":"513"
},
{
"id":257949,
"key":"_wcpdf_formatted_proforma_number",
"value":"89000513"
},
{
"id":257951,
"key":"_order_stock_reduced",
"value":"yes"
}
],
"line_items":{
"17631":{
}
},
"tax_lines":{
"17633":{
}
},
"shipping_lines":{
"17632":{
}
},
"fee_lines":[
],
"coupon_lines":[
]
}
I would like to do a check on the payment method, so I can create arguments based on that. Right now, the payment method is bacs, but how can I check that? Any idea what I need to return for that?
Upvotes: 0
Views: 108
Reputation: 681
You are dealing with a json object. You need to use json_decode ()
and access it like an normal php indexed array.
$arr = json_decode ($your_array, true);
Then access it like $arr ['payment_method'].
OR
$arr = json_decode ($your_array);
Then access it like $arr->payment_method.
Upvotes: 2
Reputation: 1048
First of all: You have a JSON encoded object. If you want to access it, you have to decode it via json_decode()
:
$array = json_decode($order, true);
// If you pass true as second parameter,
// you will get an associative array instead of an object.
What you are looking for is then
$payment_method = $array['payment_method'];
Upvotes: 1