仅在已完成订单状态的电子邮件上显示优惠券消息 [英] Displaying a coupon message on emails for completed order status only

查看:36
本文介绍了仅在已完成订单状态的电子邮件上显示优惠券消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有那个代码,它会在电子邮件订单中显示优惠券信息,如果客户尚未使用此订单中的任何产品.

我只想在已完成订单上而不是在所有邮件上显示该优惠券消息.

add_action( 'woocommerce_email_before_order_table', 'processing_order_mail_message', 20 );函数 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">享受 20% 的折扣</h2><p id="pthanks">感谢您的购买!回来使用代码Back4More"下次购买时可获得 20% 的折扣!点击此处继续购物.</p>';}

我怎样才能做到这一点?

谢谢

解决方案

使用 if 语句和2 个条件,仅适用于完成"订单状态.

<块引用>

add_action( 'woocommerce_email_before_order_table', 'completed_order_mail_message', 20 );函数已完成_order_mail_message( $order ) {如果(空( $order->get_used_coupons() )&& $order->post_status == 'wc-completed' )echo '<h2 id="h2thanks">享受 20% 的折扣</h2><p id="pthanks">感谢您的购买!回来使用代码Back4More"下次购买时可获得 20% 的折扣!点击此处继续购物.</p>';}

此代码位于活动子主题或主题的 function.php 文件中

此代码已经过测试并且完美运行

<块引用>

但是自动完成付费订单,您需要添加一些内容:
WooCommerce:自动完成付费订单(取决于付款)方法)

参考:

I've got that code that displays a coupon message in the email orders if the customer has not used any in this order.

I would like to display that coupon message only on completed order instead on all mails.

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>';
}

How can I achieve that?

Thanks

解决方案

It is possible easily to display a custom message on emails with an if statement and 2 conditions, for "complete" order status only.

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>';
}

This code goes on function.php file of your active child theme or theme

This code is tested and works perfect

BUT to autocomplete paid orders you need to add something:
WooCommerce: Auto complete paid Orders (depending on Payment methods)

Reference:

这篇关于仅在已完成订单状态的电子邮件上显示优惠券消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆