I am trying to send an email to the customer after he has used a specific promo code 'FREECLASS' while checking out.
What I do is send the customer a code 'FREECLASS' after signing up. I want the customer to get an additional custom message after he uses that code.
Based on Send an email notification when a specific coupon code is applied in WooCommerce answer code, this is what I have done up until now but it is not working.
add_action( 'woocommerce_applied_coupon', 'custom_email_on_applied_coupon', 10, 1 );
function custom_email_on_applied_coupon( $coupon_code ){
if( $coupon_code == 'FREECLASS' ){
// Get user billing email
global $user_login;
$user = get_user_by('login', $user_login );
$email = $user->billing_email;
$to = "$email"; // Recipient
$subject = sprintf( __('Coupon "%s" has been applied'), $coupon_code );
$content = sprintf( __('The coupon code "%s" has been applied'), $coupon_code );
wp_mail( $to, $subject, $content );
}
}
This is my first WooCommerce project so some help would be really appreciated.