WooCommerce echo address pin-code/ City zip from Login User

WooCommerce has a shipping address, that Customers fill shipping address form and saves on the database automatic, including postcode (zip code), city, and more.

WooCommerce echo address Postcode

In this post, we share short-codes for woo-commerce, validate built-in which is used to find appropriate shipping methods on the checkout. How woocommerce echo address from login user current address pin-code/city zip code echo.

<?php
$customer_id = get_current_user_id();

if ( ! wc_ship_to_billing_address_only() && wc_shipping_enabled() ) {
	$get_addresses = apply_filters(
		'woocommerce_my_account_get_addresses',
		array(
			'shipping' => __( 'Shipping address', 'woocommerce' ),
		),
		$customer_id
	);
}

?>

<?php foreach ( $get_addresses as $name => $address_title ) : ?>
	<?php

		$address = wc_get_account_formatted_address( $name );

	?>
<?php endforeach; ?>

<?php

echo get_user_meta( $customer_id, $name . '_postcode', true )."<br>";
echo get_user_meta( $customer_id, $name . '_city', true );

?>

In this code, they get only login user shipping address, postalcode or ZIP code, and city direct echo like (110001 and Delhi) all the shipping zone information that is a postcode and city.

That is done by providing the ‘customer_id’ as the object id and the ‘billing address’ as the object compare my account. Why? Because the results retrieved from the SQL above will provide you will an array of objects with those attributes.

Other Popular Articles...

Leave a Comment