Reputation: 41
I have a WooCommerce store that has products with multiple variations.
In the cart, it shows a thumbnail of the product variation image. This is not good, because the variation is actually just a text image, so you can't see the actual product the text is going onto.
How can I force Woo Commerce to show only the main product image, not the variation on the cart page?
Thanks!!
Upvotes: 1
Views: 4426
Reputation: 1180
Add following code in active theme's functions.php
.
function getCartItemThumbnail( $img, $cart_item ) {
if ( isset( $cart_item['product_id'] ) ) {
$product = wc_get_product($cart_item['product_id']);
if ( $product && $product->is_type( 'variable' ) ) {
// Return variable product thumbnail instead variation.
return $product->get_image();
}
}
return $img;
}
add_filter( 'woocommerce_cart_item_thumbnail', 'getCartItemThumbnail', 111, 2 );
Upvotes: 5