Skip to content

Instantly share code, notes, and snippets.

@dparker1005
Last active January 22, 2020 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dparker1005/86f7b7ccf2c79f26a80f7beb40311a81 to your computer and use it in GitHub Desktop.
Save dparker1005/86f7b7ccf2c79f26a80f7beb40311a81 to your computer and use it in GitHub Desktop.
Only allows each user to use one discount code.
<?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