Reputation: 580
I am displaying the Woocommerce product categories in my cart and checkout pages. However I am trying to get it to display just the text only and prevent it from being "clickable" - i.e. remove the link.
I have tried inspecting with browser tools and removing with CSS, but no luck. - Any help appreciated!
Here is my code used to display the category in checkout page:
add_filter( 'woocommerce_cart_item_name', 'bbloomer_cart_item_category', 99, 3);
function bbloomer_cart_item_category( $name, $cart_item, $cart_item_key ) {
$product_item = $cart_item['data'];
// make sure to get parent product if variation
if ( $product_item->is_type( 'variation' ) ) {
$product_item = wc_get_product( $product_item->get_parent_id() );
}
$cat_ids = $product_item->get_category_ids();
// if product has categories, concatenate cart item name with them
if ( $cat_ids ) $name .= '</br>' . wc_get_product_category_list( $product_item->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count( $cat_ids ), 'woocommerce' ) . ' ', '</span>' );
return $name;
}
Upvotes: 1
Views: 1173
Reputation: 498
You can remove all HTML tags from a string in PHP with the strip_tags() function. In your case you only need to remove the a tag. So you do it like this :
if ( $cat_ids ) $name .= '</br>' .strip_tags( wc_get_product_category_list( $product_item->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count( $cat_ids ), 'woocommerce' ) . ' ', '</span>' ),'<span>');
Notice the second param to strip_tags the '' to allow the tag span.
Upvotes: 1