true, 'type' => 'customer' ) ); } /** * Record a referral when a new user has been referred by an affiliate. * * @param int $user_id * @param array $params registration parameters */ public static function user_register( $user_id, $params = array() ) { extract( $params ); if ( !isset( $force ) ) { $force = false; } if ( !isset( $type ) ) { $type = null; } if ( !$force && is_admin() ) { if ( !apply_filters( 'affiliates_user_registration_on_admin', false ) ) { return; } } if ( $user = get_user_by( 'id', $user_id ) ) { $post_id = null; // Notes on registrations made on WooCommerce checkout: // Using global $post; and $post->ID just provides the ID of the first product in the shop. // The same applies for $post = get_post(); and $post->ID. // And also for $permalink = get_permalink(); and $post_id = url_to_postid( $permalink ) ); // The folllowing obtains the shop's ID on checkout and corresponding page IDs for normal other cases. $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $post_id = url_to_postid( $current_url ); if ( $post_id === 0 ) { $post_id = null; } switch ( $type ) { case 'customer' : $description = sprintf( 'Customer Registration %s', esc_html( $user->user_login ) ); break; default : $description = sprintf( 'User Registration %s', esc_html( $user->user_login ) ); } $base_amount = null; if ( AFFILIATES_PLUGIN_NAME != 'affiliates' ) { $base_amount = get_option( 'aff_user_registration_base_amount', null ); } $amount = null; if ( empty( $base_amount ) ) { $amount = get_option( 'aff_user_registration_amount', '0' ); } $currency = get_option( 'aff_user_registration_currency', Affiliates::DEFAULT_CURRENCY ); $user_registration_referral_status = get_option( 'aff_user_registration_referral_status', get_option( 'aff_default_referral_status', AFFILIATES_REFERRAL_STATUS_ACCEPTED ) ); $data = array( 'user_login' => array( 'title' => 'Username', 'domain' => 'affiliates', 'value' => $user->user_login, ), 'user_email' => array( 'title' => 'Email', 'domain' => 'affiliates', 'value' => $user->user_email, ), 'first_name' => array( 'title' => 'First Name', 'domain' => 'affiliates', 'value' => $user->first_name, ), 'last_name' => array( 'title' => 'Last Name', 'domain' => 'affiliates', 'value' => $user->last_name, ), 'base_amount' => array( 'title' => 'Base Amount', 'domain' => 'affiliates', 'value' => $base_amount ) ); if ( class_exists( 'Affiliates_Referral_WordPress' ) ) { $r = new Affiliates_Referral_WordPress(); $affiliate_id = $r->evaluate( $post_id, $description, $data, $base_amount, $amount, $currency, $user_registration_referral_status, self::REFERRAL_TYPE ); } else { $affiliate_id = affiliates_suggest_referral( $post_id, $description, $data, $amount, $currency, $user_registration_referral_status, self::REFERRAL_TYPE ); } } } } Affiliates_User_Registration::init();