K
K
Konstantin Lavrovsky2019-12-15 16:19:25
WooCommerce
Konstantin Lavrovsky, 2019-12-15 16:19:25

Why is the referral system not working?

Good evening, I am making a referral system on the site, but for some reason it works somehow crookedly.
Through the get request, I take the referrer nickname into the session and give it to a variable (while I was writing, I realized that this could be a mistake).

if (isset($_GET['referal'])) {
  session_save_path(ROOT.SLASH.'.sid');
  session_start();
  $referal = $_GET['referal'];
  $_SESSION['save_referal'] = $referal;
}
$ref_name = $_SESSION['save_referal'];

Registration goes through woocommerce, I catch it with a hook in function.php, maybe there is a registration hook itself?
And then I do it after payment.
add_action( 'woocommerce_order_status_completed', 'referral_users' );
function referral_users($ref_name){
// Данные для линка тут есть
  $link = mysqli_connect($host, $user, $password, $database) 
      or die("Ошибка " . mysqli_error($link));

  $query = "UPDATE wp_users SET user_invited ='$ref_name'";

  $s1 = mysqli_query($link, $query);

  mysqli_close($link);
}

It seems like I passed the variable to the function, uploaded it to the database, but instead of the referrer nickname it appears in the database - the order number, I don’t understand how it works, why is it being passed?
And where did I make a mistake?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question