• Resolved davidovic123

    (@davidovic123)


    Hi,

    I added the following snippet as recommended, but it seems that the code does not display the image for the product that has the variation attribute.
    It only works for the “Simple product”.

    function example_product_image( $product ) {    
        if( ( '' !== $product->get_id() ) && has_post_thumbnail( $product->get_id() ) ) {
             echo get_the_post_thumbnail( $product->get_id(), array( 40, 40 ), array( 'loading' => false ) );
        }
    }
    add_action( 'wcdn_order_item_before', 'example_product_image' );

    Please,

    How to make this snippet work for “Variable Product”?
    And,
    How to display a description text next to the image, aligned vertically, and avoid that the image is surrounded by the text?

    Thank you very much,

    • This topic was modified 3 years, 10 months ago by davidovic123.
    • This topic was modified 3 years, 10 months ago by davidovic123.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moksha Shah

    (@mokshasharmila13)

    Hi @davidovic123,

    For display the image for the product that has the variation attribute and will add short description below the image. please add the below code in your active theme’s functions.php file or using a plugin like Code Snippets:

    function add_product_image( $product_name, $item ) {
    	$product_id    = $item['product_id'];
    	$product_instance = wc_get_product($product_id);
        $product_short_description = $product_instance->get_short_description();   
    	$product_image = wp_get_attachment_image_src( get_post_thumbnail_id( $product_id ) );
    	?>
    	<img src="<?php echo esc_url( $product_image[0] ); ?>" width="50" height="50" >
    	<?php
    	echo '<br>'. $product_short_description;
    	echo '<br>' . $product_name;
    } add_filter( 'wcdn_order_item_name', 'add_product_image', 10, 2 );
    

    Regards,
    Moksha.

    Thread Starter davidovic123

    (@davidovic123)

    Hi @mokshasharmila13,

    Thanks for your reply & for the code snippet.
    It works.

    Thank you very much for your support, Have a great day,

    Moksha Shah

    (@mokshasharmila13)

    Hi @davidovic123,

    Good to know that your problem is resolved 🙂.
    It would be great if you can give a review for the plugin & the support on https://ww.wp.xz.cn/support/plugin/woocommerce-delivery-notes/reviews/#new-post. That would be very helpful.

    Regards,
    Moksha.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Variable Product Image’ is closed to new replies.