Madivad
Madivad

Reputation: 3337

removing thumbnail and links in woocommerce mini-cart, filter not working

I'm trying to remove product thumbnails from the WooCommerce StoreFront theme. I have every instance of them removed from the storefront generally, including the cart, but not the minicart in the main navigation/menubar.

The hooks are the same they are just not applying.

my filter

add_filter( 'woocommerce_cart_item_thumbnail', '__return_false' );

from cart.php line 68:

$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );

from mini-cart.php line 38:

$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );

This works for the cart where I am trying to remove it, but doesn't remove it from the minicart.


As a second example of a minicart problem, I am also removing the product link from the title. This works and it removes the link from the cart item (as well as in the checkout when reviewing the order), but still not from the minicart.

filter:

add_filter( 'woocommerce_cart_item_name', 'mad_remove_cart_product_link', 1, 3 );
function mad_remove_cart_product_link( $product_link, $cart_item, $cart_item_key ) {
    $product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
    return "0" . $product->get_title() . "0";
}

on line 83 of cart.php

echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key );

on line 37 of mini-cart.php:

$product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );

The visible "0" at each end of the product title in the filter is just for debugging. They obviously appear in the cart, the review area of the checkout, but not in the minicart

Upvotes: 1

Views: 3479

Answers (2)

shah
shah

Reputation: 1

Add this to your child theme functions.php

add_filter( 'woocommerce_mini_cart_item_name_permalink', '__return_null' );

Upvotes: 0

Ashok Kumar Nath
Ashok Kumar Nath

Reputation: 111

Just add another product to the cart and you will see your code working. WooCommerce uses sessionStorage, so as long the cart is not updated, it doesn't send any new ajax request, rather uses the value from sessionStorage :)

Upvotes: 1

Related Questions