WooCommerce WPGens Referral in every email

Viewed 40

I use a Referral plugin for WooCommerce developed by WPGens (I already submitted a ticket but I am not premium so I don't have many hopes

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 );

But this add the information to the bottom of the WooCommerce Mails is there a way to show the same information but above the Order Details? In terms of marketing it would be first thing customers see.

1 Answers

Yes, there is WC woocommerce_email_before_order_table filter hook that you can use. that will display information above the order table. code will go in your active theme functions.php file.

function gens_raf_customer_email( $order, $sent_to_admin, $plain_text, $email ) {
    $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_before_order_table', 'gens_raf_customer_email', 30, 4 );
Related