Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Created October 17, 2022 08:53
Show Gist options
  • Select an option

  • Save goranefbl/ee8a69274cdc5eae163b492f4ee3fcdf to your computer and use it in GitHub Desktop.

Select an option

Save goranefbl/ee8a69274cdc5eae163b492f4ee3fcdf to your computer and use it in GitHub Desktop.
user registration reward
<?php
add_action( 'user_register', 'generate_coupon', 10, 1 );
function generate_coupon( $user_id ) {
if(isset($_COOKIE["gens_raf"])) {
$referral_code = $_COOKIE["gens_raf"];
global $wpdb;
$results = $wpdb->get_results($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='gens_referral_id' AND meta_value = %s", $referral_code));
if(!empty($results)) {
$user_id = (int)$results[0]->user_id;
}
// You got ID of user that referred friend, now create a coupon and assign it to him. Check WPGens_RAF_Coupons class.
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment