I
I
Ilya Derevyannykh2021-10-21 18:30:10
WordPress
Ilya Derevyannykh, 2021-10-21 18:30:10

Are there plugins for creating referral links?

Are there any plugins similar to Order Master? Found only in quotations manually it is necessary to hand over links.
If anyone knows you need a solution that creates a personal account and creates a referral link itself

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-10-21
@artzolin

There are enough options . In general, this is done quite simply by hand
1. Register get variable ref

add_filter( 'query_vars', 'add_query_vars' );
function add_query_vars( $qvars ) {

  $qvars[] = 'ref';
  return $qvars;

}

2. In the personal account, create a field that can be copied. Write the user id in the get parameter 3. On init check the value of the get parameter, if the user is not authorized or his id differs from the get request, then write the setcookie() referral id
https://example.ru/?ref=48
function set_new_cookie() {
  if ( $ref = get_query_var( 'ref', false ) ) {
    //setting your cookies there
  }
}
add_action( 'init', 'set_new_cookie' );

4. On the user_register hook, check if the specified cookie exists and write it to the meta for further processing
add_action( 'user_register', 'referral_registration_save', 10, 1 );
function referral_registration_save( $user_id ) {

  if ( isset( $_COOKIE['ref'] ) )
    add_user_meta( $user_id, 'ref', $_COOKIE['ref'], true );
  
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question