有两种查找客户/用户送货地址的方法-
function get_user_shipping_address(){
global $user;
$default_pid =commerce_addressbook_get_default_profile_id($user->uid,'shipping');
获取个人资料ID后,您可以加载个人资料并获取客户名称和地址
$profile_load = commerce_customer_profile_load($default_pid);
$first_line = $profile_load->commerce_customer_address['und'][0]['name_line'];
$landmark = $profile_load->commerce_customer_address['und'][0]['sub_premise'];
$postal_code = $profile_load->commerce_customer_address['und'][0]['postal_code'];
$state = $profile_load->commerce_customer_address['und'][0]['locality'];
$add[] = $first_line . ' ' . $landmark . ' ' . $postal_code . ' ' . $state;
return $add;
}
第二种方式,如果您有$ order
function get_default_address_of_customer_by_order_id($order) {
$order1 = commerce_order_load($order);
$shipping_id = $order1->commerce_customer_shipping['und'][0]['profile_id'];
$address = commerce_customer_profile_load($shipping_id);
$first_line = $address->commerce_customer_address['und'][0]['name_line'];
$landmark = $address->commerce_customer_address['und'][0]['sub_premise'];
$postal_code = $address->commerce_customer_address['und'][0]['postal_code'];
$state = $address->commerce_customer_address['und'][0]['locality'];
$add[] = $first_line . ' ' . $landmark . ' ' . $postal_code . ' ' . $state;
return $add;
}