Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('init', function () {
- if(!session_id()) {
- session_start();
- }
- $wreferrer = filter_input( INPUT_GET, 'wreferrer' );
- if( $wreferrer ) {
- $affiliate = wcfm_get_affiliate_by_referrer( $wreferrer );
- if( $affiliate ) {
- if (!session_id()) {
- session_start();
- }
- $_SESSION['wreferrer']=absint($affiliate);
- }
- }
- }, 1);
- add_action( 'wcfmmp_new_store_created', function( $store_id ) {
- $member_user = new WP_User(absint($store_id));
- $member_user->add_role('wcfm_affiliate');
- if(isset($_SESSION['wreferrer'])) {
- update_user_meta( $store_id, '_wcfm_affiliate', $_SESSION['wreferrer'] );
- unset($_SESSION['wreferrer']);
- }
- $member_user->remove_role('wcfm_vendor');
- $member_user->add_role('wcfm_vendor');
- }, 50 );
- function prepare_affiliate_user( $user_id, $role ) {
- if($role!=='wcfm_affiliate') return;
- $affiliate_code = get_user_meta( $user_id, 'affiliate_code', true);
- if($affiliate_code) return;
- $user = get_user_by('id', $user_id);
- $affiliate_code = substr( md5( $user->user_email . '+' . $user_id ), 0, 10 );
- update_user_meta( $user_id, 'affiliate_code', $affiliate_code );
- // Affiliate Commission
- $global_commission = get_option( 'wcfm_affiliate_commission', array() );
- $global_commission['rule'] = 'global';
- update_user_meta( $user_id, 'wcfm_affiliate_commission', $global_commission );
- update_user_meta( $user_id, 'wcfm_affiliate_application_status', 'approved' );
- update_user_meta( $user_id, 'show_admin_bar_front', false );
- update_user_meta( $user_id, 'wcemailverified', 'true' );
- }
- add_action( 'set_user_role', 'prepare_affiliate_user', 10, 2 );
- add_action( 'add_user_role', 'prepare_affiliate_user', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement