从 WooCommerce 结帐页面获取送货地址?

Getting Shipping Address from WooCommerce Checkout Page?

我有点卡住了。

我已经弄清楚如何通过以下方法检索分配给客户个人资料的地址:

print_r(WC()->customer);

但我终究无法弄清楚要获取用于在订单结帐页面上计算运费的送货地址,需要什么挂钩或任何一个。

我的问题是:

Is this something that is possible to get?

感谢您的帮助!

获取送货地址的方法有多种。

一个解决方案使用global $woocommerce

global $woocommerce;
echo $woocommerce->customer->get_billing_address();
echo $woocommerce->customer->get_billing_city();
echo $woocommerce->customer->get_billing_state();

另一种使用 global $current_user 的解决方案:

global $current_user;

$billing_address_1 = get_user_meta($current_user->ID, 'billing_address_1', true);
$billing_city = get_user_meta($current_user->ID, 'billing_city', true);
$billing_state = get_user_meta($current_user->ID, 'billing_state', true);

echo $billing_address_1;
echo $billing_city;
echo $billing_state;

另一种使用WC()的解决方案:

echo WC()->customer->get_billing_address_1();
echo WC()->customer->get_billing_city();
echo WC()->customer->get_billing_state();

另一种使用 session 的解决方案:

$customer_data = WC()->session->get('customer');
echo $customer_data['address_1'];
echo $customer_data['city'];
echo $customer_data['state'];