0

On my Wordpress website, using WooCommerce, on the Checkout page, I am seeing the photos appear above the list of products at Checkout. How do I make them appear IN the list of products, as shown?

enter image description here

This is what I have at the moment:

add_action('woocommerce_checkout_before_order_review', 'displays_cart_products_feature_image');
function displays_cart_products_feature_image() {
    foreach ( WC()->cart->get_cart() as $cart_item ) {
        $item = $cart_item['data'];
        if(!empty($item)){
            $product = new WC_product($item->id);
            // $image = wp_get_attachment_image_src( get_post_thumbnail_id( $product->ID ), 'single-post-thumbnail' );
            echo $product->get_image();

            // to display only the first product image uncomment the line bellow
            // break;
        }
    }
}

This is related to Get Cart products id on checkout WooCommerce page, to display product images.

Thanks!

enter image description here

1 Answers1

1

Instead of woocommerce_checkout_before_order_review, we can use woocommerce_cart_item_name filter like this:

add_action('woocommerce_cart_item_name', 'displays_cart_products_feature_image', 10, 2 );
function displays_cart_products_feature_image( $cart_item_name, $cart_item ) {

    return ( is_checkout() ) ? $cart_item['data']->get_image() . $cart_item_name : $cart_item_name;

}

what this will do is put the image before the product name. Something like this image below:

reigelgallarde.me

Still not what we need right? Yes but it's the closest thing we can get. And just some CSS will fixed the problem.

.woocommerce-checkout-review-order-table .cart_item .product-name img {
    float: right;
}

Will look like this below: enter image description here

Reigel Gallarde
  • 64,198
  • 21
  • 121
  • 139