Her is what I came up with, if some of you are interrested. Mistake spotters welcome…
<?php
/**
* Implements hook_token_info().
* @ http://fredparke.com/blog/create-your-own-tokens-drupal-7
*/
function address_token_token_info() {
$info = array();
// Define a new token type.
$info['types']['my_custom_tokens'] = array(
'name' => t('My custom tokens'),
'description' => t('A token type for my custom tokens.'),
);
// Define any new tokens.
$info['tokens']['my_custom_tokens']['user_name_line'] = array(
'name' => t('Current user\'s full name'),
'description' => t('A token I use to display the full name.'),
);
$info['tokens']['my_custom_tokens']['user_thoroughfare'] = array(
'name' => t('Current user\'s thoroughfare'),
'description' => t('A token I use to display the thoroughfare.'),
);
$info['tokens']['my_custom_tokens']['user_postal_code'] = array(
'name' => t('Current user\'s postal code'),
'description' => t('A token I use to display the postal code.'),
);
$info['tokens']['my_custom_tokens']['user_locality'] = array(
'name' => t('Current user\'s postal code'),
'description' => t('A token I use to display the locality.'),
);
$info['tokens']['my_custom_tokens']['user_country'] = array(
'name' => t('Current user\'s postal code'),
'description' => t('A token I use to display the country.'),
);
$info['tokens']['my_custom_tokens']['user_billing-address'] = array(
'name' => t('Current user\'s billing address'),
'description' => t('A token I use to display the whole address.'),
);
return $info;
}
/**
* Implements hook_tokens().
*/
function address_token_tokens($type, $tokens, array $data = array(), array $options = array()) {
/* Variables to use in foreach within the fonction
@ http://stackoverflow.com/questions/8506359/how-to-assign-foreach-loop-to-a-variable#8506477
Elements declared via AddressBook
@ http://drupal.stackexchange.com/questions/116453/how-to-get-default-drupal-commerce-billing-shipping-customer-profile-in-code#146244
@ https://www.drupal.org/node/1245956#comment-5593970
Nested arrays
@ http://www.w3schools.com/php/php_arrays_multi.asp
*/
global $user;
$default_pid=commerce_addressbook_get_default_profile_id($user->uid,'billing');
$profiles = commerce_customer_profile_load_multiple(array(), array('uid' => $user->uid));
$user_name_line = $profiles[$default_pid]->commerce_customer_address['und']['0']['name_line'];
$user_thoroughfare = $profiles[$default_pid]->commerce_customer_address['und']['0']['thoroughfare'];
$user_postal_code = $profiles[$default_pid]->commerce_customer_address['und']['0']['postal_code'];
$user_locality = $profiles[$default_pid]->commerce_customer_address['und']['0']['locality'];
$user_country = $profiles[$default_pid]->commerce_customer_address['und']['0']['country'];
$replacements = array();
if ($type == 'my_custom_tokens') {
// Loop through the available tokens.
foreach ($tokens as $name => $original) {
// Find our custom tokens by name.
switch ($name) {
case 'user_name_line':
// Work out the value of our token.
$value = $user_name_line;
// Give our token it's value!
$replacements[$original] = $value;
break;
case 'user_thoroughfare':
// Work out the value of our token.
$value = $user_thoroughfare;
// Give our token it's value!
$replacements[$original] = $value;
break;
case 'user_postal_code':
// Work out the value of our token.
$value = $user_postal_code;
// Give our token it's value!
$replacements[$original] = $value;
break;
case 'user_locality':
// Work out the value of our token.
$value = $user_locality;
// Give our token it's value!
$replacements[$original] = $value;
break;
case 'user_country':
// Work out the value of our token.
$value = $user_country;
// Give our token it's value!
$replacements[$original] = $value;
break;
case 'user_billing-address':
// Work out the value of our token.
$value = $user_thoroughfare.'<br />'.$user_postal_code.'<br />'.$user_locality.'<br />'.$user_country;
// Give our token it's value!
$replacements[$original] = $value;
break;
}
}
}
return $replacements;
}