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.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityHow 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.
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';
}
}