Home / Forums / WoodMart support forum / Use Main Image in Cart (not variation)
Home › Forums › WoodMart support forum › Use Main Image in Cart (not variation)
Use Main Image in Cart (not variation)
- This topic has 9 replies, 2 voices, and was last updated 6 years, 2 months ago by
Artem Temos.
-
AuthorPosts
-
April 8, 2020 at 3:10 am #185271

flossymooParticipantHi all!
I need to show the main product image in my cart page, not the variation image as the variation is just a colour swatch. I need to show the product main image instead. How can I make the theme show the main product image instead of the variation image?Thank you for your help!
FlossyApril 8, 2020 at 6:48 am #185305Hello,
It is standard WooCommerce behavior and there is no option to disable this. Try to apply the solution suggested here https://stackoverflow.com/questions/42941816/showing-the-main-product-image-in-the-cart-thumbnail-instead-of-the-variation-i
Kind Regards
April 8, 2020 at 7:08 am #185313
flossymooParticipantThanks, Artem! I tried this in the functions.php file, but it comes back with an error saying it won’t update that file, that there’s an error in communicating with it. Is there some reason why the functions.php file won’t update via the dashboard in wordpress? Any ideas? Thanks!!
April 8, 2020 at 7:56 am #185339Could you please send us a screenshot of the error and how your file looks when you try to save it?
April 8, 2020 at 11:30 am #185414
flossymooParticipantSure, attached. You can see the code I am adding (from the referenced site), and the response when I try to save it.
Attachments:
You must be logged in to view attached files.April 8, 2020 at 1:32 pm #185416You need to edit files using FTP or via your hosting control panel. If you don’t have this information, contact your hosting provider for help.
April 10, 2020 at 10:06 am #185876
flossymooParticipantThanks, Artem! Managed to get it to take, but now I come back with ‘Nonce_Failure’. I’m no genius, but I am guessing there’s something wrong with the code from that page that you referenced, but I don’t know what. I placed the code at the end of the functions.php file, as given:
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 );
Honestly the end looks a bit odd to me, but I don’t know why. Thanks!
April 10, 2020 at 11:02 am #185894The code from the article seems to be correct and we don’t see any PHP errors. Sorry, but additional code customizations like this are out of our theme support scope.
April 10, 2020 at 12:42 pm #185934
flossymooParticipantThanks for your help – Knowing it was ok code was really helpful, and I managed to sort it out myself! I really appreciate the assistance! Happy Easter!
April 10, 2020 at 12:45 pm #185937Thank you! Happy Easter to you too!
-
AuthorPosts
The topic ‘Use Main Image in Cart (not variation)’ is closed to new replies.
- You must be logged in to create new topics. Login / Register