Getting Shipping Address from WooCommerce Checkout Page?
i'm a little bit stuck.
I've figured out how to retrieve the addresses assigned to a customers profile via the follow:
print_r(WC()->customer);
But I can't for the life of me figure out what the hook or whichever is required in order to get the shipping address that is being used for the calculation of shipping on the order checkout page. Is this something that is possible to get?
Thank you for the help!
Solutions
There are several ways to get the shipping address .
One solution using
global $woocommerce
:
global $woocommerce;
echo $woocommerce->customer->get_billing_address();
echo $woocommerce->customer->get_billing_city();
echo $woocommerce->customer->get_billing_state();
Another solution using
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;
Another solution using
WC()
:
echo WC()->customer->get_billing_address_1();
echo WC()->customer->get_billing_city();
echo WC()->customer->get_billing_state();
Another solution using
session
:
$customer_data = WC()->session->get('customer');
echo $customer_data['address_1'];
echo $customer_data['city'];
echo $customer_data['state'];