仅在电子邮件上显示已完成订单状态的优惠券信息


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个条件的自定义消息,仅用于"完成"订单状态。

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

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

BUT to autocomplete paid orders你需要添加一些东西:
WooCommerce:自动完成付款订单(取决于付款方式)

参考:

  • 仅当客户未使用优惠券时,才在加工订单电子邮件中添加优惠券
  • WooCommerce:自动完成付款订单(取决于付款方式)