I am using a plugin to send custom referral codes in the email orders but now I found that every order email has the code inserted.
function gens_raf_customer_email( $order, $sent_to_admin, $plain_text ) {
$user_id = ( version_compare( WC_VERSION, '2.7', '<' ) ) ? $order->customer_user : $order->get_customer_id();
if( ! empty( $user_id ) && ( get_user_meta($user_id, "gens_referral_id", true) ) != '' ){
$code = get_user_meta($user_id, "gens_referral_id", true);
} else {
$code = ( version_compare( WC_VERSION, '2.7', '<' ) ) ? $order->billing_email : $order->get_billing_email();
}
if( $plain_text ){
_e('Your referral code is: ','gens-raf') . $code;
} else {
echo '<p style="text-align:center;margin-top:10px;">Your referral code is: ' .get_home_url() .'?raf='. $code . '</p>';
}
} add_action('woocommerce_email_customer_details', 'gens_raf_customer_email', 30, 3 );
I was messing around with
if ( $email->id == 'customer_completed_order' )
But gave me error from the php code builder. The main issue is to send that email only to completed and/or processing orders instead of refunded, cancelled and so on.
Thank you!