Formatting output of token I have Drupal Commerce, and it sends confirmation emails after product is sold. In those emails are tokens. I have token [commerce-order:created] and I'm interested if is there any conveniant way to change a formatting of that date.
If [commerce-order:created] is a date token, then you can use [commerce-order:created:custom:&lt;the format you want to apply&gt;], where &lt;the format you want to apply&gt; is the string format accepted by date().

Otherwise, the more generic way to alter tokens implemented by other modules is implementing hook_tokens_alter().

function mymodule_tokens_alter(&amp;$replacements, $context) {
  $options = $context['options'];

  $sanitize = !empty($options['sanitize']);
  $langcode = !empty($options['language']-&gt;language) ? $options['language']-&gt;language : NULL;

  if ($context['type'] == 'commerce-order') {
    foreach ($context['tokens'] as $name =&gt; $original) {
      switch ($name) {
        case 'created':
          // Set a value for $sanitized and $new_value.
          $replacements[$original] = $sanitize ? $sanitized : $new_value;
      }
    }
  }
}


Notice that in my code:


$sanitized is the sanitized value to assign to the token, used only when $sanitize is TRUE
$new_value is the new value for the token, used to obtain the value of $sanitized