[英]Woocommerce remove product category link from checkout/cart page
I am displaying the Woocommerce product categories in my cart and checkout pages. 我正在购物车和结帐页面中显示Woocommerce产品类别。 However I am trying to get it to display just the text only and prevent it from being "clickable" - ie remove the link. 但是我试图让它只显示文本,并防止它被“可点击” -即删除链接。
I have tried inspecting with browser tools and removing with CSS, but no luck. 我尝试使用浏览器工具进行检查,并使用CSS进行删除,但是没有运气。 - 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;
}
You can remove all HTML tags from a string in PHP with the strip_tags() function. 您可以使用strip_tags()函数从PHP中的字符串中删除所有HTML标签。 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. 注意第二个参数strip_tags',以允许标签跨度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.