1

如果客户未在此订单中使用任何优惠券,我将获得在电子邮件订单中显示优惠券消息的代码。

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

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

我怎样才能做到这一点?

谢谢

4

1 回答 1

2

可以轻松地在电子邮件上显示带有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 文件中

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

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

参考:

于 2016-08-16T13:22:13.707 回答