Become a Referral Partner

Share Learning Loft with people you know. When they book using your code, they save 10% — and you earn 10% too.

Letters and numbers only. This is what people will enter to get their discount.

Step 3 — Add a new Code Snippet for the processing logic (Title: "LL Referral Signup Processing", Run: Everywhere): php global $ll_referral_signup_error; $ll_referral_signup_error = ''; add_action('template_redirect', function() { global $ll_referral_signup_error; if (!is_page('referral-signup') || !isset($_POST['ll_referral_signup_submit'])) return; if (!isset($_POST['ll_referral_signup_nonce']) || !wp_verify_nonce($_POST['ll_referral_signup_nonce'], 'll_referral_signup_action')) { $ll_referral_signup_error = 'Security check failed. Please try again.'; return; } if (!ll_is_referral_program_open()) { $ll_referral_signup_error = 'The Learning Loft Referral Program is not currently accepting new sign-ups.'; return; } $first_name = sanitize_text_field($_POST['ll_first_name']); $last_name = sanitize_text_field($_POST['ll_last_name']); $email = sanitize_email($_POST['ll_email']); $password = $_POST['ll_password']; $password_confirm = $_POST['ll_password_confirm']; $raw_code = sanitize_text_field($_POST['ll_referral_code'] ?? ''); $code = strtoupper(preg_replace('/[^A-Za-z0-9]/', '', $raw_code)); if (empty($first_name) || empty($last_name) || empty($email) || empty($password) || empty($code)) { $ll_referral_signup_error = 'Please fill in all required fields.'; return; } if ($password !== $password_confirm) { $ll_referral_signup_error = 'Passwords do not match.'; return; } if (strlen($password) < 8) { $ll_referral_signup_error = 'Password must be at least 8 characters.'; return; } if (!is_email($email) || email_exists($email)) { $ll_referral_signup_error = 'That email is invalid or already registered. Try logging in instead.'; return; } // Check code uniqueness across all referral partners global $wpdb; $existing_code = $wpdb->get_var($wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'll_referral_code' AND meta_value = %s", $code )); if ($existing_code) { $ll_referral_signup_error = "The code \"$code\" is already taken. Please choose a different one."; return; } // Create the username from the email $username = sanitize_user(strtolower($first_name . '.' . $last_name), true); $base_username = $username; $i = 1; while (username_exists($username)) { $username = $base_username . $i; $i++; } $user_id = wp_insert_user(array( 'user_login' => $username, 'user_email' => $email, 'user_pass' => $password, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $first_name . ' ' . $last_name, 'role' => 'referral_partner', )); if (is_wp_error($user_id)) { $ll_referral_signup_error = 'Account creation failed: ' . $user_id->get_error_message(); return; } update_user_meta($user_id, 'll_referral_code', $code); update_user_meta($user_id, 'll_referral_status', 'pending_stripe'); update_user_meta($user_id, 'll_referral_signup_date', current_time('Y-m-d')); // Log them in wp_set_current_user($user_id); wp_set_auth_cookie($user_id); // Immediately create their Stripe account + onboarding link, and send them there $stripe_result = ll_create_referral_stripe_link($user_id); if (!$stripe_result['success']) { wp_die( 'Your Learning Loft account was created successfully, but we ran into an issue setting up your payout account. ' . 'Please contact us at advising@learningloftadvising.com so we can finish setting this up for you.

' . 'Details: ' . esc_html($stripe_result['error']) . '' ); } wp_redirect($stripe_result['url']); exit; }); /** * Create a Stripe Connect account + onboarding link for a referral partner, * during self-signup. Separate from the admin-only Stripe Onboarding Link * Generator button — this one only ever acts on the CURRENTLY LOGGED IN user's * own account, never an arbitrary user ID passed from outside. */ function ll_create_referral_stripe_link($user_id) { if (!defined('LL_STRIPE_SECRET_KEY')) { return array('success' => false, 'error' => 'Stripe is not configured.'); } $user = get_userdata($user_id); if (!$user) { return array('success' => false, 'error' => 'Invalid user.'); } // Step 1: create the connected account $account_response = wp_remote_post('https://api.stripe.com/v1/accounts', array( 'headers' => array( 'Authorization' => 'Bearer ' . LL_STRIPE_SECRET_KEY, 'Content-Type' => 'application/x-www-form-urlencoded', ), 'body' => array( 'type' => 'express', 'email' => $user->user_email, 'capabilities' => array( 'transfers' => array('requested' => 'true'), ), ), 'timeout' => 30, )); if (is_wp_error($account_response)) { return array('success' => false, 'error' => $account_response->get_error_message()); } $account_body = json_decode(wp_remote_retrieve_body($account_response), true); if (empty($account_body['id'])) { $err = isset($account_body['error']['message']) ? $account_body['error']['message'] : 'Unknown error creating Stripe account.'; return array('success' => false, 'error' => $err); } $account_id = $account_body['id']; update_user_meta($user_id, 'll_stripe_account_id', $account_id); // Step 2: create the onboarding link // Return URL includes ll_stripe_return so the existing Auto-Activation // listener (from "LL Referral Partner Auto-Activation") picks it up automatically. $return_url = add_query_arg('ll_stripe_return', $account_id, home_url()); $link_response = wp_remote_post('https://api.stripe.com/v1/account_links', array( 'headers' => array( 'Authorization' => 'Bearer ' . LL_STRIPE_SECRET_KEY, 'Content-Type' => 'application/x-www-form-urlencoded', ), 'body' => array( 'account' => $account_id, 'refresh_url' => home_url(), 'return_url' => $return_url, 'type' => 'account_onboarding', ), 'timeout' => 30, )); if (is_wp_error($link_response)) { return array('success' => false, 'error' => $link_response->get_error_message()); } $link_body = json_decode(wp_remote_retrieve_body($link_response), true); if (empty($link_body['url'])) { $err = isset($link_body['error']['message']) ? $link_body['error']['message'] : 'Unknown error creating onboarding link.'; return array('success' => false, 'error' => $err); } return array('success' => true, 'url' => $link_body['url']); }