[英]Woocommerce remove product category link from checkout/cart page
我正在購物車和結帳頁面中顯示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;
}
您可以使用strip_tags()函數從PHP中的字符串中刪除所有HTML標簽。 在你的情況,你只需要刪除的標簽。 所以你這樣做:
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>');
注意第二個參數strip_tags',以允許標簽跨度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.