Skip to content

Instantly share code, notes, and snippets.

@akshuvo
Forked from riotxoa/functions.php
Created October 5, 2020 23:12
Show Gist options
  • Save akshuvo/64e0af494af9dd714caed0469fd4c85a to your computer and use it in GitHub Desktop.
Save akshuvo/64e0af494af9dd714caed0469fd4c85a to your computer and use it in GitHub Desktop.
WooCommerce Coupons Fix: email restrictions
/*
WooCommerce email restriction for coupons does not work. This fix corrects it.
Include this code snippet in your theme or plugin.
*/
add_filter( 'woocommerce_coupon_is_valid', 'wc_riotxoa_coupon_is_valid', 10, 2 );
if ( ! function_exists( 'wc_riotxoa_coupon_is_valid' ) ) {
function wc_riotxoa_coupon_is_valid( $result, $coupon ) {
$user = wp_get_current_user();
$restricted_emails = $coupon->get_email_restrictions();
return ( in_array( $user->user_email, $restricted_emails ) ? $result : false );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment