当前位置: 首页 > 知识库问答 >
问题:

Woocommerce从结帐/购物车页面删除产品类别链接

朱通
2023-03-14

我在购物车和结账页面中显示Woocommerce产品类别。然而,我试图让它只显示文本,并防止它被“点击”-即删除链接。

我试过用浏览器工具检查,用CSS删除,但没有成功。-感谢您的帮助!

以下是用于在签出页面中显示类别的代码:

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;

}

共有1个答案

尉迟招
2023-03-14

可以使用strip_tags()函数从PHP中的字符串中删除所有HTML标记。在您的情况下,您只需要删除a标记。所以你是这样做的:

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>');

请注意,第二个参数用于剥离“”上的_标记以允许标记跨度。

 类似资料: