Huy ròm
Huy ròm

Reputation: 1

Show product image + name on checkout page

How can i put code in order to show both Picture and Image of my product??

function isa_woo_cart_attributes($cart_item, $cart_item_key) {
    global $product; 
    if (is_cart()){ 
        echo "<style>#checkout_thumbnail{display:none;}</style>"; 
    } 
    $item_data = $cart_item_key['data']; 
    $post = get_post($item_data->id); 
    $thumb = get_the_post_thumbnail($item_data->id, array( 32, 50)); 
    echo '<div id="checkout_thumbnail" style="float: left; padding-right: 8px">' . $thumb . '</div> '; 
} 
add_filter('woocommerce_cart_item_name', isa_woo_cart_attributes, 10, 2);

And

$product = new WC_product($item_data->id);
echo $product->name;
echo $product->price;

Upvotes: 0

Views: 381

Answers (1)

itzmekhokan
itzmekhokan

Reputation: 2770

Replace your codes by the follows code snippet -

function isa_woo_cart_attributes( $product_name, $cart_item ) {
    $_product = $cart_item['data'];
    $product_permalink = $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '';
    $thumbnail = $_product->get_image();
    printf( '<a href="%s">%s</a>%s', esc_url( $product_permalink ), $thumbnail, $product_name );
} 
add_filter('woocommerce_cart_item_name', 'isa_woo_cart_attributes', 99, 2);

Code goes to your active theme's functions.php

Upvotes: 2

Related Questions