Commerce already defines two menu items in the Navigation menu:

  • Shopping cart - 'cart' - enabled by default, static
  • Shopping cart - 'cart/my' - disabled by default, dynamic

'cart/my' uses a custom title callback, 'commerce_cart_menu_item_title' that builds a dynamic menu link in the form: Shopping cart (2 items)

If I want to add a new menu item for the shopping cart to the User Menu, what's the proper way to do this? Do I first need to duplicate a menu item, then override the duplicate?

Ideally, I would be able to set my own title callback so that I can optionally build a dynamic menu in any format I choose.

1 Answer 1


You can create a new menu programatically through menu hooks, and a great source for sample code and explanation is the menu_example portion of the Examples Module.

For example

function mymodule_menu() {
     $items['cart/new_menu_item'] = array(
    'title' => 'Shopping cart (# items)',
    'title callback' => 'mymodule_new_menu_item_title',
    'title arguments' => array(TRUE),
    'page callback' => 'mymodule_new_menu_item_redirect',
    'access arguments' => array('access content'),
    'type' => MENU_SUGGESTED_ITEM, 
  return $items;

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.