仅针对已完成的订单状态在电子邮件中显示优惠券消息
Displaying a coupon message on emails for completed order status only
我有 如果客户未使用此订单中的任何优惠券,它会在电子邮件订单中显示优惠券消息。
我只想在 已完成 订单上显示该优惠券消息,而不是在所有邮件上显示。
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>';
}
我怎样才能做到这一点?
谢谢
可以很容易地在电子邮件中显示带有 if
语句和 2 个条件的自定义消息,用于 "complete" 订单仅状态。
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
此代码已经过测试并且可以完美运行
BUT to autocomplete paid orders you need to add something:
参考:
我有
我只想在 已完成 订单上显示该优惠券消息,而不是在所有邮件上显示。
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>';
}
我怎样才能做到这一点?
谢谢
可以很容易地在电子邮件中显示带有 if
语句和 2 个条件的自定义消息,用于 "complete" 订单仅状态。
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
此代码已经过测试并且可以完美运行
BUT to autocomplete paid orders you need to add something:
参考: