在 WooCommerce 完成订单电子邮件通知的页脚中添加图像

Adding an image near the footer on WooCommerce completed orders email notification

我正在尝试使用此代码在 WooCommerce 已完成订单电子邮件通知的页脚附近插入图片,但不幸的是它不起作用!

这是我正在尝试的代码:

    <?php
    echo ("Hello");
    ?>
    <div>
        <img src="myPic.jpg" alt="myPic" />
    </div>

有什么线索吗?

谢谢

您最好在 woocommerce_email_customer_details 动作挂钩中使用自定义挂钩函数,例如,这样:

add_action( 'woocommerce_email_customer_details', 'custom_image_near_email_footer' , 50, 4);
function custom_image_near_email_footer( $order, $sent_to_admin, $plain_text, $email ) {    
    // For customer order notification with "completed" status
    if ( 'customer_completed_order' == $email->id ) 
        echo '<div style="text-align:center;">
            <img src="'.home_url( "wp-content/uploads/2017/05/myPic.jpg" ).'" alt="myPic"/>
        </div>';
}

You could also use woocommerce_email_footer action hook instead which have only one argument ($email argument).

代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。

此代码已经过测试,适用于 WooCommerce 版本 2。6.x 和 3.0+