1

I have overridden woocommerce customer-completed-order.php

<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

do_action( 'woocommerce_email_header', $email_heading, $email ); 
?>

<p><?php printf( __( "Your recent order has been completed.<br> ,'woocommerce' ) ); ?></p>

How to add image to the end of the email?

I tried

<?php echo wp_get_attachment_image( 1096 ,add_image_size('logo-size', 219,98) );  ?>

but only white space is displayed in the received email.

<?php echo wp_get_attachment_image( 1096); ?>

displays it in a cropped size.

EDIT added full customer-completed-order.php

<?php


if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

foreach ($order->get_items() as $item_id => $item) {
    $product_name = $item['name']; // product name
}
/**
 * @hooked WC_Emails::email_header() Output the email header
 * 
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); 
?>

<p><?php printf( __( "Your recent order has been completed, 'woocommerce' ), $product_name ); ?></p>

2 Answers 2

1

wp_get_attachement_image wants the second argument to be an array of width, height

like: array('900', '1200').

So in your example if attachment id is 1096, width is 219, and height is 98, it would be:

<?php echo wp_get_attachment_image( 1096, array( 219, 98) );  ?>

If you're looking for the un-cropped, full image: Instead of using wp_get_attachment, try wp_get_attachment_image_src and pass a size argument of "full."

This returns an array:

(false|array) Returns an array (url, width, height, is_intermediate), or false, if no image is available.

So we get the url like so:

$attachment_id = '1906';
$image_array = wp_get_attachment_image_src( $attachment_id, 'full' );
echo '<img src="'. $image_array[0] .'" >';
5
  • hi, thanks. tried your option with wp_get_attachment_image_src. image is still not seen. (
    – rok
    May 13, 2017 at 21:57
  • Hmm... did you try the <?php echo wp_get_attachment_image( 1096, array( 219, 98) ); ?>
    – hwl
    May 13, 2017 at 22:00
  • yes, the same effect
    – rok
    May 13, 2017 at 23:49
  • 1
    Can you post your complete version of /customer-completed-order.php ?
    – hwl
    May 14, 2017 at 17:47
  • Ok.. I do not see do_action(footer) etc., More importantly, I don't see where you are placing the not working wp_get_attachement... you're asking about.
    – hwl
    May 16, 2017 at 17:21
0

This solution works.

<?php


if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

foreach ($order->get_items() as $item_id => $item) {
    $product_name = $item['name']; // product name
}
/**
 * @hooked WC_Emails::email_header() Output the email header
 * 
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); 
?>

<p><?php printf( __( "Your recent order has been completed, 'woocommerce' ), $product_name ); ?></p>

<p>
  <?php echo wp_get_attachment_image( 1096, array('219', '98'), "", array( 
    'name' => 'logo',
    'align' => 'left', // Not supported in HTML5
    'border' => '0', // Not supported in HTML5
    'width' => '219',
    'height' => '98'
  ) ); ?> 
</p>

After adding

<p>
  <?php echo wp_get_attachment_image( 1096, array('219', '98'), "", array( 
    'name' => 'logo',
    'align' => 'left', // Not supported in HTML5
    'border' => '0', // Not supported in HTML5
    'width' => '219',
    'height' => '98'
  ) ); ?> 
</p>

The images are displayed in email.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.