2

I want to change the label in the attached image, that is from Commerce Kickstart. I need to change that text depending on the role of the user.

If the user has role1 then the text will be "order total" & if user has role2 then the text should change to "Quote total". Any idea?

I tried to debug with Devel to see where to change the label but I could not find it.

enter image description here

2 Answers 2

2

You can use the hook_commerce_price_formatted_components_alter() The following example checks if VAT has been applied to the order total and changes the string accordingly:

/**
 * Implements hook_commerce_price_formatted_components_alter().
 *
 * Alters somes text at the checkout form
 *
 * @param $components
 * @param $price
 * @param $entity
 */
function mymodule_commerce_price_formatted_components_alter(&$components, $price, $entity) {
  $pieces = explode('/',current_path());
  if(!isset($components['tax|ch_vat']) && $pieces[0] == 'checkout'){
    $components['commerce_price_formatted_amount']['title'] = t('Order total (excluding VAT)');
  }
}
2
  • IT worked!! could you tell me how did you find the right hook?
    – svelandiag
    Commented Dec 2, 2014 at 18:50
  • Many sleepless nights :) The modulename.api.php file usually contains the module's hooks. From then on, it is a matter of experimenting
    – Mike
    Commented Dec 2, 2014 at 23:07
-1

One way would be to implement hook_entity_view_alter() in a custom module of yours.

<?php
/**
 * Implements hook_entity_view_alter().
 */
function YOURMODULE_entity_view_alter(&$build, $type) {
  switch ($type) {
    case 'commerce_order':
      /**
       * In here implement your alter logic
       */
      break;
  }
}

To determine what exactly to alter, after the 'in here...' comment you can use debug($build); or dpm($build); (if devel installed).

To see the user roles:

global $user;
debug($user->roles);

Similar issue here.

1
  • 1
    It would be really nice if people who downvote answers explain why.
    – Wtower
    Commented Dec 2, 2014 at 19:07

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.