由于打印数组的方式,我在PHP方面不太好。我返回一个名为$ order的var,我得到以下内容:
{
"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",
"billing":{
"first_name":"Michael",
"last_name":"Darmanin",
"company":"TEST TEST",
"address_1":"Europaplein 300",
"address_2":"",
"city":"Utrecht",
"state":"",
"postcode":"3526WG",
"country":"NL",
"email":"theassociator@gmail.com",
"phone":"+31308781101"
},
"shipping":{
"first_name":"Michael",
"last_name":"Darmanin",
"company":"TEST TEST",
"address_1":"Europaplein 300",
"address_2":"",
"city":"Utrecht",
"state":"",
"postcode":"3526WG",
"country":"NL"
},
"payment_method":"bacs",
"payment_method_title":"Bankoverschrijving",
"transaction_id":"",
"customer_ip_address":"83.85.155.182",
"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",
"value":"theassociator@gmail.com"
},
{
"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",
"customer_ip_address":"83.85.155.182",
"customer_ip_address_country":"NL",
"self_certified":"no"
},
"exemption":{
"vat_number":"NL234077232B02",
"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":[
]
}
我想检查一下付款方式,所以我可以根据它创建参数。现在,付款方式是bacs,但我该怎么检查呢? 知道我需要返回什么吗?
答案 0 :(得分:2)
您正在处理 json对象。您需要使用json_decode ()
并像普通的php索引数组一样访问它。
$arr = json_decode ($your_array, true);
然后像$arr ['payment_method'].
或
$arr = json_decode ($your_array);
然后像$arr->payment_method.
答案 1 :(得分:1)
首先:您有一个 JSON 编码对象。如果要访问它,则必须通过json_decode()
解码:
$array = json_decode($order, true);
// If you pass true as second parameter,
// you will get an associative array instead of an object.
您正在寻找的是
$payment_method = $array['payment_method'];