Ad
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.
My question is:
Is this something that is possible to get?
Thank you for the help!
Ad
Answer
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'];
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad