Skip to content

Instantly share code, notes, and snippets.

@Mikodes
Created June 1, 2023 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mikodes/a56c2405c3b89ac3a956b8c7e94ff380 to your computer and use it in GitHub Desktop.
Save Mikodes/a56c2405c3b89ac3a956b8c7e94ff380 to your computer and use it in GitHub Desktop.
add_action( 'user_register', 'affiliatewp_custom_track_registration', 10, 1 );
function affiliatewp_custom_track_registration( $user_id ) {
// Comprueba si existe la cookie de afiliado
if (isset($_COOKIE['affwp_ref'])) {
$affiliate_id = $_COOKIE['affwp_ref'];
// Obtiene el correo electrónico del usuario
$user = get_userdata($user_id);
$user_email = $user->user_email;
// Comprueba si el usuario ya es un afiliado
if (!affwp_is_affiliate($user_id)) {
// Si no es un afiliado, añádelo como afiliado
affwp_add_affiliate(array(
'user_id' => $user_id,
'status' => 'active',
'payment_email' => $user_email,
'rate' => '20', // Por ejemplo, un 20% de comisión
'referral_rate_type' => 'percentage'
));
}
// Añade la referencia
$amount = 0; // No hay un total de pedido en este caso
$description = 'Registro de usuario';
$reference = $user_id; // Usa el ID de usuario como referencia
$referral_id = affwp_add_referral(array(
'affiliate_id' => $affiliate_id,
'amount' => $amount,
'description' => $description,
'reference' => $reference,
'status' => 'unpaid'
));
// Si la referencia se añadió correctamente, marca la referencia como completada
if ($referral_id) {
affwp_set_referral_status($referral_id, 'unpaid');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment