@update 2:新订单大部分时间处于 'on-hold' 状态,而不是 'Processing'。
在这种情况下,请改用它:
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' )
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>';
}
或者处理'on-hold'和'processing'状态使用这个:
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>';
}
此代码位于您的活动子主题或主题的 function.php 文件中
此代码经过测试且功能齐全
测试:
要显示电子邮件订单的状态,您可以在此行中添加函数:
echo '<p>The status of this order is: ' . $order->post_status . '</p>';
要显示使用的优惠券(如果有的话)添加:
echo '<p>Coupons used in this order are: '; print_r( $order->get_used_coupons() ); echo '</p>'
(这只是为了测试目的)。
原答案:
是的,很容易添加带有 2 个条件的 if 语句。
第一个检测是否在订单中使用的订单中没有使用优惠券:
empty( $order->get_used_coupons() )
第二个会检测订单是否处于“处理”状态:
$order->post_status == 'wc-processing'
如果条件匹配,则使用**'woocommerce_email_before_order_table'** 钩子显示您的消息:
这是您自定义的代码 sn-p:
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-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>';
}
此代码位于您的活动子主题或主题的 function.php 文件中
此代码经过测试且功能齐全