In my effort to improve this code I would like to make it work depending on the sum of all purchases a user has made until then. That is to say, if the whole quantity is less than <100€ send a kind of email, if it is between 100€-200€ another one and if it is more then >200€ another different.
Here it is the code:
add_action( 'woocommerce_email_before_order_table', 'completed_order_mail_message', 20 );
function completed_order_mail_message( $order ) {
// Getting order user data to get the user roles
$user_data = get_userdata($order->customer_user);
if ( $order->post_status == 'wc-completed' && in_array('customer', $user_data->roles) )
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>';
}
How can I achive it?
Thanks in advance.
You could try something like this:
This code should work
Code goes in function.php file of your active child theme (active theme or in any plugin file).