woocommerce: avoid “succesful” conversion Mail for Test orders

in order to check the link functionality, I have recently clicked on the affiliate link of one of my affiliate users sites. Any time I do a (test) order, the affiliate gets contributed. How can I unlink my account with this affiliate? I will never want to contribute anyone, when an admin or a shop manager does a purchase in my shop. Even if they clicked on an affiliate link before…

Posted in

Comments

One response to “woocommerce: avoid “succesful” conversion Mail for Test orders”

  1. George Avatar

    Hi Felix,

    Sorry for the late response.

    There is a filter availiable affiliates_record_referral you can see the description here.
    You can get the referral data concerning the referral to be recorded and check if the user involved is the administrator or the shop manager.
    If so, no referral will be recorded. You can use the hook below simply by putting the code in your functions.php file of your child theme.


    add_filter( 'affiliates_record_referral', 'gt_refuse_referrals_on_roles', 10, 2 );
    function gt_refuse_referrals_on_roles( $result, $referral_data ) {

    $order_id = $referral_data['post_id'];
    $order = new WC_Order( $order_id );

    $usr = (int)$order->user_id;
    $current_user = get_userdata( $usr );
    $role_value = $current_user->roles;

    foreach ( $role_value as $role_element ) {
    if ( $role_element == 'administrator' || $role_element == 'shop_manager' ) {
    $result = false;
    }
    }

    return $result;
    }

    You can try it yourself and let me know if it works.

    Kind regards,
    George

Share