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

时间:2019-02-25 14:19:24

标签: php wordpress templates woocommerce email-notifications

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

这是正常的模板显示:

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

1 个答案:

答案 0 :(得分: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

现在应该可以了。