Last active
January 22, 2020 13:39
-
-
Save dparker1005/86f7b7ccf2c79f26a80f7beb40311a81 to your computer and use it in GitHub Desktop.
Only allows each user to use one discount code.
This file contains 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
<?php | |
/* | |
Each user can only use one discount code. | |
Add this to your active theme's functions.php or a custom plugin. | |
*/ | |
function my_pmpro_check_discount_code($okay, $dbcode, $level_id, $code) | |
{ | |
global $wpdb, $current_user; | |
$codes_used = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->pmpro_discount_codes_uses WHERE user_id = '" . $current_user->ID . "'" ); | |
if ( $codes_used > 0 ) { | |
return 'You have already used a discount code.'; | |
} | |
return $okay; | |
} | |
add_filter('pmpro_check_discount_code', 'my_pmpro_check_discount_code', 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment