Created
June 1, 2023 11:48
-
-
Save Mikodes/a56c2405c3b89ac3a956b8c7e94ff380 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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