在Woocommerce电子邮件通知中显示产品图像

在Woocommerce电子邮件通知中显示产品图像,woocommerce,Woocommerce,在Woocommerce上,我已将电子邮件订单详细信息php模板文件中的$show_image变量更改为true,但我仍然无法获得电子邮件通知中显示的图像: <div style="margin-bottom: 40px;"> <table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial,

在Woocommerce上,我已将电子邮件订单详细信息php模板文件中的
$show_image
变量更改为
true
,但我仍然无法获得电子邮件通知中显示的图像:

<div style="margin-bottom: 40px;">
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
    <thead>
        <tr>
            <th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Product', 'woocommerce' ); ?></th>
            <th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Quantity', 'woocommerce' ); ?></th>
            <th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Price', 'woocommerce' ); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php
        echo wc_get_email_order_items( $order, array( // WPCS: XSS ok.
            'show_sku'      => $sent_to_admin,
            'show_image'    => true,
            'image_size'    => array( 100, 100 ),
            'plain_text'    => $plain_text,
            'sent_to_admin' => $sent_to_admin,
        ) );
        ?>
    </tbody>
    <tfoot>
        <?php
        $totals = $order->get_order_item_totals();

        if ( $totals ) {
            $i = 0;
            foreach ( $totals as $total ) {
                $i++;
                ?>
                <tr>
                    <th class="td" scope="row" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo wp_kses_post( $total['label'] ); ?></th>
                    <td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo wp_kses_post( $total['value'] ); ?></td>
                </tr>
                <?php
            }
        }
        if ( $order->get_customer_note() ) {
            ?>
            <tr>
                <th class="td" scope="row" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Personal Message:', 'woocommerce' ); ?></th>
                <td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php echo wp_kses_post( wptexturize( $order->get_customer_note() ) ); ?></td>
            </tr>
            <?php
        }
        ?>
    </tfoot>
</table>


要在电子邮件通知中显示图像,请将更改还原为原始模板,并改用:

add_filter( 'woocommerce_email_order_items_args', 'custom_email_order_items_args', 10, 1 );
function custom_email_order_items_args( $args ) {
    $args['show_image'] = true;

    return $args;
}
要将产品链接添加到图像和项目名称(可选),您将使用:

add_filter( 'woocommerce_order_item_thumbnail', 'add_email_order_item_permalink', 10, 2 ); // Product image
add_filter( 'woocommerce_order_item_name', 'add_email_order_item_permalink', 10, 2 ); // Product name
function add_email_order_item_permalink( $output_html, $item, $bool = false ) {
    // Only email notifications
    if( is_wc_endpoint_url() )
        return $output_html;

    $product   = $item->get_product();

    return '<a href="'.esc_url( $product->get_permalink() ).'">' . $output_html . '</a>';
}

经过测试,也能正常工作。

我没有在电子邮件中获取图像超链接工作正常,但图像不工作添加我在电子邮件中获取图像的方式显示间隙但没有获取图像应将全部代码添加到functions.php文件中,或者添加过滤器中的代码(“woocommerce\u order\u item\u缩略图”、“添加电子邮件\u order\u item\u permalink”,10,2);//产品图像这一行添加到functions.php文件实际上我已经复制了function.php文件本身的所有代码,但仍然无法在电子邮件中看到产品图像。我也在电子邮件模板中还原了代码,但仍然无法看到图像我在电子邮件中也遇到了同样的问题,图片显示为损坏的图像。我尝试我创建了一个不同的电子邮件帐户,结果发现它与这些设置有关,而不是与代码有关。我为我尝试的第一个电子邮件帐户启用了html电子邮件,但仍然如此。无论如何,这可能对遇到此问题的人有所帮助。
$args['image_size'] = array( 48, 48 );