[DRUPAL 7][UBERCART] How to remove the link of the titles and images of items in cart page

| | 1 min read

In a recent project, one of the client requirements was to remove the link of the cart-image which appears in shopping cart page. In drupal, when a node is added to cart, it will be automatically linked to the corresponding node page. He wanted to hide it because, we were not using the default node page for the products. If you want to know, how we removed the link from the cart-image, you may follow the stepss below.

  • Step 1 : In your module_form_alter() , check if the form's id is uc_cart_view_form .(This is the ubercart's form displaying in cart page.)
  • Step 2 : Loop through each element of the form.
  • Step 3 : Strip the html elements in the image and title.

The function with the above steps is shown below for reference.

function mymodulename_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'uc_cart_view_form') { 
	foreach ($form['items'] as $key => $item) { //loops through each form element
	  if (!empty($item['desc']['#markup'])) {
		$form['items'][$key]['desc']['#markup'] = strip_tags($item['desc']['#markup']); //*strips the html from product's title
		$form['items'][$key]['image']['#path'] =''; //Replaces the title's path attribute as NULL, which will make the image 'link-less'

**The strip_tags() strips the html and php tags from a given string.

This code worked for me. Hope this helps you too.