As described in this post I'd like to invert the row between shipping service and VAT calculation.

I don't know how to use that hook... Can someone tells me more?


EDIT: I followed the example. I created the module, it's active and running but I see that nothing happens.

I tell you what I did (it's all in italian): - Created posizione_iva.info file with this content

core = "7.x"
description = "Modulo che sposta la riga dell'IVA dopo tutti i valori imponibili."
name = "Posizione IVA"
  • Created posizione_iva.module and copied the function

I have a doubt about this condition if (substr($name, 0, 3) == 'iva') Where can I find the right component name? I tried vat, VAT, iva, tax...

I use the default Drupal Commerce Kickstart installation and the "tax" module.

1 Answer 1


I assume that you know how to create a module and what a hook is, you can use hook_commerce_price_component_type_info_alter like this:

function mymodule_checkout_commerce_price_formatted_components_alter(&$components, $price, $entity) {
  if (isset($components['commerce_price_formatted_amount']['weight'])){

    // Get the row weight of total sum.
    $last_weight = $components['commerce_price_formatted_amount']['weight'];

    // Increase the row weight of the total row, so we can place the vat directly before.        
    $last_weight = $last_weight + 100;
    $components['commerce_price_formatted_amount']['weight'] = $last_weight;

  if (is_array($components) && count($components)>0){
    foreach ($components as $name => &$component){

      // Set the weight of the VAT row to the last position before the total sum.
      if (substr($name, 0, 3) == 'vat'){
        $component['weight'] = ($last_weight-1);

  • Thank you for your reply, I don't know how to create a module but I see that there's a lot of documentations about that, so I try to use your code to make my own module, thank you very much!!!
    – SmurfXXX
    Commented Jul 31, 2015 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.