pcoder pcoder - 1 year ago 440
PHP Question

woocommerce cart custom thumbnail image image in cart

i want to show custom thumbnail images in cart .

i made product with custom attribute say imageurl

i used below hook to make it work

function custom_new_product_image($cart_object) {
$a = '<img src="imageurlhere" />';
return $a;

add_filter( 'woocommerce_cart_item_thumbnail', 'custom_new_product_image' );

my code works well i put static url in place of imageurlhere but i want to pass custom product attribute image url .

i am able to get image url with below code :


Answer Source
function custom_new_product_image( $_product_img, $cart_item, $cart_item_key ) {
    $id     =   $cart_item["product_id"];
    $img    =   wc_get_product_terms( $id, "pa_imageurl", array( 'fields' => 'names' ) );
    $a      =   '<img src="'.$img[0].'" />';
    return $a;

add_filter( 'woocommerce_cart_item_thumbnail', 'custom_new_product_image', 10, 3 );

I hope, this is what you expect!!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download