READ FIRST: This code needs to be added at the end of the functions.php file. If you are familiar with editing functions.php, feel free to continue reading. If you haven’t done this before, adding this code in the wrong place might bring the site down and the only way to access it is by editing functions.php file again via FTP. Feel free to contact us if you need help!
In order for referral coupons to work with Wallet Coupons add-on for TeraWallet, just add code below to the functions.php file:
add_action( 'gens_generate_user_coupon', function($couponId) { update_post_meta( $couponId, '_is_coupon_cashback', 'yes' ); }, 10, 1);
If you want to add amount directly to TeraWallet, the code below should do that for you. Also please note, this code works with fixed amount reward, not percentage.
// Add wallet credit
add_action('gens_before_generate_user_coupon', function($user_id, $type, $order) {
$amount = get_option($type === "friend" ? 'gens_raf_friend_coupon_amount' : 'gens_raf_coupon_amount');
// Add to TeraWallet
if (function_exists('woo_wallet')) {
woo_wallet()->wallet->credit($user_id, $amount, 'Referral Reward');
}
}, 10, 3);
// Prevent coupon generation
add_filter('gens_raf_generate_coupon', function($generate, $order_id) {
// Return false to prevent coupon generation
return false;
}, 10, 2);