Search code examples
phpwordpresswoocommercehook-woocommerceemail-notifications

WooCommerce order received image does not change its size


I have a code which should change the image of email orders for WooCommerce I based this on guides on all sources online:

function sww_add_wc_order_email_images( $table, $order ) {
    ob_start();
    
    $template = $plain_text ? 'emails/plain/email-order-items.php' : 'emails/email-order-items.php';
    wc_get_template( $template, array(
        'order'                 => $order,
        'items'                 => $order->get_items(),
        'show_download_links'   => false,
        'show_sku'              => false,
        'show_purchase_note'    => false,
        'show_image'            => true,
        'image_size'            => array( 150, 150 )
    ) );

    return ob_get_clean();
}
add_filter( 'woocommerce_email_order_items_table', 'sww_add_wc_order_email_images', 10, 2 );

But it seems the images do not change its size. I am not sure why the image size does not work.


Solution

  • The code that you have shared seems to work, but you can use the woocommerce_email_order_items_args hook as an alternative.

    So you get:

    function my_email_order_items_args( $args ) {
        $args['show_image'] = true;
        $args['image_size'] = array( 150, 150 );
    
        return $args;
    }
    add_filter( 'woocommerce_email_order_items_args', 'my_email_order_items_args', 10, 1 );