Ad
Hide Thumbnail For Specific Product Categories In WooCommerce Cart
I'm trying to hide the image in the WooCommerce Cart for certain categories. I found that adding this code removes all thumbnails from the Cart:
add_filter( 'woocommerce_cart_item_thumbnail', '__return_false' );
I'm trying (and failing), to only remove this for certain categories, using the following code.
function WooCartImage($woocommerce_cart_item_thumbnail) {
if ( is_product_category(63) ) {
$woocommerce_cart_item_thumbnail = '__return_false';
}
return $woocommerce_cart_item_thumbnail;
}
add_filter( 'woocommerce_cart_item_thumbnail', 'WooCartImage' );
I'm not sure where I'm going wrong with this and if anyone has a hint, that would be great!
Ad
Answer
The woocommerce_cart_item_thumbnail
filter hook contains 3 arguments,
the 2nd is $cart_item
, so you can use $cart_item['product_id']
in combination with has_term()
So you get:
function filter_woocommerce_cart_item_thumbnail( $product_image, $cart_item, $cart_item_key ) {
// Specific categories: the term name/term_id/slug. Several could be added, separated by a comma
$categories = array( 63, 15, 'categorie-1' );
// Has term (product category)
if ( has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) {
$product_image = '';
}
return $product_image;
}
add_filter( 'woocommerce_cart_item_thumbnail', 'filter_woocommerce_cart_item_thumbnail', 10, 3 );
Ad
source: stackoverflow.com
Related Questions
- → CORS missmatch because of http
- → Building sitemap for 2 wordpress install under 1 domain
- → How to remove empty elements after class?(jQuery)
- → Get width of an element and apply to another relative to the first one?
- → How to remove caption p class from wordpress?
- → 301 Redirection from no-www to www in wordpress
- → Laravel 5 routing using prefix
- → WordPress - Header position Top, Left &Right
- → how to add rel=nofollow to some specific external links in wordpress
- → octobercms install error: database is not empty?
- → How to edit the index page of wordpress theme?
- → How to select a Post Type (Wordpress) to pass a filter in head?
- → What sort of URL structure should be used to display AMP HTML vs vanilla HTML
Ad