Hi,

I am making a site where the prices (taxes) will change based on shipping country. I want to show the correct price on the product pages and the user are on first visit asked for shipping country and I store this in a cookie. But, for logged in users with a stored address it would be very useful to buypass this question and retrieve the stored shipping country.

I have briefly looked at commerce_addressbook.module and found the commerce_addressbook_get_default_profile_id function that retrieves the ID of the profile, but is there an easy way to retrieve the default shipping address for example?

Comments

mglaman’s picture

Category: Feature request » Support request
Issue summary: View changes
Status: Active » Closed (fixed)

You would do something like the following snippet to get addressfield data.

$profile_id = commerce_addressbook_get_default_profile_id($user->uid, 'shipping');
$profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile_id);
$address = $profile_wrapper->get('commerce_customer_address')->value();