我有一个这样做的功能:
$order = new WC_Order($order_id); $customer = new WC_Customer( $order_id );
如何从中获得客户的详细信息?
我已经尝试过文件中的所有内容,但不知何故,只有一些细节存在,但其余的则不例外
$data['Address'] = $customer->get_address() . ' ' . $customer->get_address_2(); $data['ZipCode'] = $customer->get_postcode();
是空的.
干
var_dump($customer)
生产:
object(WC_Customer)#654 (2) { [“_data”:protected]=> array(14) { [“country”]=> string(2) “IT” >[“state”]=> string(0) “” [“postcode”]=> string(0) “” [“city”]=> string(0) “” [“address”]=> >string(0) “” [“address_2”]=> string(0) “” [“shipping_country”]=> string(2) “IT”
[“shipping_state”]=> string(2) “BG” [“shipping_postcode”]=> string(0) “” [“shipping_city”]=> >string(0) “” [“shipping_address”]=> string(0) “” [“shipping_address_2”]=> string(0) “”
[“is_vat_exempt”]=> bool(false) [“calculated_shipping”]=> bool(false) } ?
[“_changed”:”WC_Customer”:private]=> bool(false) }
正如你所看到的,城市是现在,但其余的是空的.我已经在WP_userMeta和客户的管理面板中检查了所有的数据.
有什么想法吗?
尝试过$customer = new WC_Customer();和全球$woocommerce; $customer = $woocommerce->客户;即使以非管理员用户身份登录,我仍然会收到空的地址数据.
原文链接:https://www.f2er.com/php/138446.html我的解决方案如下:
function mwe_get_formatted_shipping_name_and_address($user_id) { $address = ''; $address .= get_user_Meta( $user_id,'shipping_first_name',true ); $address .= ' '; $address .= get_user_Meta( $user_id,'shipping_last_name',true ); $address .= "\n"; $address .= get_user_Meta( $user_id,'shipping_company','shipping_address_1','shipping_address_2','shipping_city','shipping_state','shipping_postcode','shipping_country',true ); return $address; }