Home Forums WoodMart support forum Use Main Image in Cart (not variation)

Use Main Image in Cart (not variation)

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #185271

    flossymoo
    Participant

    Hi 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!
    Flossy

    #185305

    Artem Temos
    Keymaster

    Hello,

    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

    #185313

    flossymoo
    Participant

    Thanks, 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!!

    #185339

    Artem Temos
    Keymaster

    Could you please send us a screenshot of the error and how your file looks when you try to save it?

    #185414

    flossymoo
    Participant

    Sure, 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.
    #185416

    Artem Temos
    Keymaster

    You 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.

    #185876

    flossymoo
    Participant

    Thanks, 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!

    #185894

    Artem Temos
    Keymaster

    The 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.

    #185934

    flossymoo
    Participant

    Thanks 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!

    #185937

    Artem Temos
    Keymaster

    Thank you! Happy Easter to you too!

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Use Main Image in Cart (not variation)’ is closed to new replies.