根据订单状态自定义Woocommerce电子邮件通知内容

问题描述 投票:1回答:1

我正在尝试根据自定义“已发货”订单状态自定义电子邮件通知...

这是正常的模板显示:

enter image description here

这是我的代码:

<?php if( ! $order->has_status('shipped') ) { ?> 
<p><?php printf( esc_html__( 'Your %s order has been delivered to your provided shipping address and we marked its status to <b>completed</b>. Let us know if you have any questions.', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p> 
<?php } ?>

但现在我有一个重复:

enter image description here

我做错了什么?如何避免重复?

我的emails/customer-completed-order.php模板(提取)的代码结构:

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

/*
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<?php /* translators: %s: Site title */ ?>
<?php if( ! $order->has_status('shipped') ) { ?> 
<p><?php printf( esc_html__( 'Your %s order has been delivered to your provided shipping address and we marked its status to <b>completed</b>. Let us know if you have any questions.', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p> 
<?php } ?>
<p><?php printf( esc_html__( 'Your %s order has been marked complete on our side.', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p>
<?php
php wordpress templates woocommerce email-notifications
1个回答
1
投票

您需要通过以下内容替换您的实际模板结构(您有一个重复的行):

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

/*
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<?php /* translators: %s: Site title */ ?>
<?php if( ! $order->has_status('shipped') ) { ?> 
<p><?php printf( esc_html__( 'Your %s order has been delivered to your provided shipping address and we marked its status to <b>completed</b>. Let us know if you have any questions.', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p> 
<?php } ?>
<?php

现在它应该工作。

© www.soinside.com 2019 - 2024. All rights reserved.