Woocommerce: get shipping zip code to calculate shipping cost
I am developing a new shipping method that calculates the speed based on the package weight, volume and zip code of the customers ... Ive had no problem finding the basket information of the calculate_shipping function, but when I try to get the zip code from the customer it seems to be returns blank. how can I get this information at runtime to calculate the final cost?
public function calculate_shipping( $package ) {
GLOBAL $woocommerce;
$items = $woocommerce->cart->get_cart();
$cliente = $woocommerce->customer;
$peso = $woocommerce->cart->cart_contents_weight;
$customer_postcode = $woocommerce->customer->get_shipping_postcode();
}
Solved:
$customer_postcode = get_user_meta( get_current_user_id(), 'shipping_postcode', true );
+3
source to share
4 answers
global $woocommerce;
$customer = new WC_customer();
$customer_id = $customer->ID
$get_customer_shipping_pincode = get_user_meta($customer_id,"shipping_postcode",true);
$get_customer_billing_pincode = get_user_meta($customer_id,"billing_postcode",true);
if the user is logged in (for register user),
$get_customer_shipping_pincode = get_user_meta(get_current_user_id(),"shipping_postcode",true);
$get_customer_billing_pincode = get_user_meta(get_current_user_id(),"billing_postcode",true);
0
source to share