Php 仅针对已完成订单状态在电子邮件上显示优惠券消息

Php 仅针对已完成订单状态在电子邮件上显示优惠券消息,php,wordpress,woocommerce,orders,email-notifications,Php,Wordpress,Woocommerce,Orders,Email Notifications,如果客户在此订单中未使用任何优惠券,我会在电子邮件订单中显示优惠券消息 我只想在已完成的订单上显示优惠券信息,而不是在所有邮件上显示 add_action( 'woocommerce_email_before_order_table', 'processing_order_mail_message', 20 ); function processing_order_mail_message( $order ) { if ( empty( $order->get_used_coupo

如果客户在此订单中未使用任何优惠券,我会在电子邮件订单中显示优惠券消息

我只想在已完成的订单上显示优惠券信息,而不是在所有邮件上显示

add_action( 'woocommerce_email_before_order_table', 'processing_order_mail_message', 20 );
function processing_order_mail_message( $order ) {
    if ( empty( $order->get_used_coupons() ) && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-processing' ) )
        echo '<h2 id="h2thanks">Get 20% off</h2><p id="pthanks">Thank you for making this purchase! Come back and use the code "<strong>Back4More</strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';
}
add_action('woocommerce_-email_-before_-order_-table','processing_-order_-mail_-message',20);
处理订单邮件消息的函数($order){
如果(空($order->get_used_coups())&&($order->post_status=='wc on hold'| |$order->post_status=='wc processing'))
echo“获得20%的折扣”

感谢您购买此商品!请返回并使用代码“Back4More”在下次购买时获得20%的折扣!单击此处继续购物。

”; }
我怎样才能做到这一点


感谢

您可以轻松地在电子邮件上显示一条自定义消息,其中包含一个
if
语句和两个条件,仅用于“完成”订单状态。

add_action('woocommerce_-email_-before_-order_-table','completed_-order_-mail_-message',20);
功能完成\u订单\u邮件\u消息($order){
如果(空($order->get_used_coups())&&&$order->post_status=='wc completed')
echo“获得20%的折扣”

感谢您购买此商品!请返回并使用代码“Back4More”在下次购买时获得20%的折扣!单击此处继续购物。

”; }
这段代码位于活动子主题或主题的function.php文件中

此代码经过测试,工作完美

但是要自动完成付费订单您需要添加一些内容:

参考:

add_action( 'woocommerce_email_before_order_table', 'completed_order_mail_message', 20 );
function completed_order_mail_message( $order ) {
    if ( empty( $order->get_used_coupons() ) && $order->post_status == 'wc-completed' )
        echo '<h2 id="h2thanks">Get 20% off</h2><p id="pthanks">Thank you for making this purchase! Come back and use the code "<strong>Back4More</strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';
}