@update 2: New orders are most often in status , but not in . In this case, use instead: '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>';
}
Or process as 'on-hold'AND 'Processing'statuses :
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>';
}
This code continues in the functions.php file of your active child theme or theme.
:
, :
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>'
( ).
:
, if .
, , :
empty( $order->get_used_coupons() )
, "":
$order->post_status == 'wc-processing'
, ** 'woocommerce_email_before_order_table' ** hook:
:
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>';
}
functions.php