I'm looking to setup an affiliate program, starting with the email notifications like when someone applies the coupon code of a an affiliate user.
For example:
I have tried to use (without any luck): $order->get_used_coupons()
Then once order is completed, an email notification will be sent again: "order was completed with exclusive code".
You can try to use a custom function hooked in woocommerce_applied_coupon
action hook (fired each time a coupon is applied).
Here is just a functional example that will send an email when a coupon is applied (the email address name recipient is set with the coupon name).
You will need to customize it for your needs:
add_action( 'woocommerce_applied_coupon', 'custom_email_on_applied_coupon', 10, 1 );
function custom_email_on_applied_coupon( $coupon_code ){
if( $coupon_code == 'bob' ){
$to = "[email protected]"; // Recipient
$subject = sprintf( __('Coupon "%s" has been applied'), $coupon_code );
$content = sprintf( __('The coupon code "%s" has been applied by a customer'), $coupon_code );
wp_mail( $to, $subject, $content );
}
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.