Следующий код скроет «удалить товар» из корзины для определенной категории продуктов (которую вы определите во 2-й функции) :
// Custom conditional function that checks for categories (including parent)
function has_product_categories( $product_id, $categories ) {
// Initializing
$parent_term_ids = $categories_ids = array();
$taxonomy = 'product_cat';
// Convert categories term names and slugs to categories term ids
foreach ( $categories as $category ){
if( is_numeric( $category ) ) {
$categories_ids[] = (int) $category;
} elseif ( term_exists( sanitize_title( $category ), $taxonomy ) ) {
$categories_ids[] = get_term_by( 'slug', sanitize_title( $category ), $taxonomy )->term_id;
}
}
// Loop through the current product category terms to get only parent main category term
foreach( get_the_terms( $product_id, $taxonomy ) as $term ){
if( $term->parent > 0 ){
$parent_term_ids[] = $term->parent; // Set the parent product category
$parent_term_ids[] = $term->term_id; // (and the child)
} else {
$parent_term_ids[] = $term->term_id; // It is the Main category term and we set it.
}
}
return array_intersect( $categories_ids, array_unique($parent_term_ids) ) ? true : false;
}
// Hiding "remove item" for specific product category
add_filter('woocommerce_cart_item_remove_link', 'filter_cart_item_remove_link', 20, 2 );
function filter_cart_item_remove_link( $button_link, $cart_item_key ){
// HERE your specific products categories
$categories = array( 'clothing' );
// Get the current cart item
$cart_item = WC()->cart->get_cart()[$cart_item_key];
// If the targeted product is in cart we remove the button link
if( has_product_categories( $cart_item['product_id'], $categories ) )
$button_link = '';
return $button_link;
}
Код помещается в файл function.php вашей активной дочерней темы (или активной темы).Проверено и работает.