How do you hook into the 'checkout' link in the user menu?

If there is an item in the basket, want to be able to add a class to the 'checkout' link.

Ideally from the theme template and not hacking the core.


1 Answer 1


Use this function in your custom module to return a bool for determining if there items in the basket/cart.

function items_on_cart(){
global $user;
$cart = commerce_cart_order_load($user->uid);
$line_items = count($cart->commerce_line_items) ? true : false;
return $line_items;

Then in your theme template do the following...

function YOURTHEME_menu_link(array $variables) {

    $element = $variables['element'];
    $sub_menu = '';
    $name_id = strtolower(strip_tags($element['#title']));  

    // add class to checkout link if basket active
    if ($name_id == 'checkout') {
        if (YOURMODULE_items_on_cart()) {
          $element['#localized_options']['attributes']['class'][] = 'active';

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.