从Woocommerce检索订单信息时,它声明它应该是一个数组,请参阅..
http://docs.woothemes.com/wc-apidocs/class-WC_Order.html#_get_shipping_address
而是返回逗号分隔的字符串。
查看Woocommerce核心代码中的功能......
public function get_shipping_address() {
if ( ! $this->shipping_address ) {
if ( $this->shipping_address_1 ) {
// Formatted Addresses
$address = array(
'address_1' => $this->shipping_address_1,
'address_2' => $this->shipping_address_2,
'city' => $this->shipping_city,
'state' => $this->shipping_state,
'postcode' => $this->shipping_postcode,
'country' => $this->shipping_country
);
$joined_address = array();
foreach ( $address as $part ) {
if ( ! empty( $part ) ) {
$joined_address[] = $part;
}
}
$this->shipping_address = implode( ', ', $joined_address );
}
}
return $this->shipping_address;
}
我可以看到使用implode创建字符串,而不修改此函数如何调用此函数并将$ address作为数组检索? (如果可能的话?)
原因是我可以分解返回的值,但地址中的逗号会破坏它。
答案 0 :(得分:2)
回答我自己的问题的习惯......
所以要接收一个字符串作为上面的解释,你会这样做......
$order = new WC_Order($order_id);
echo $order->get_shipping_address(); //Road , Street, City, County, Postcode, Country
如果你想收到单独的行,你可以这样做......
$order = new WC_Order($order_id);
echo $order->shipping_city; //London
echo $order->shipping_country; //GB
IMO后来会更有用!