Last active
November 8, 2022 14:24
-
-
Save Bobz-zg/29ec5fa13aafc46a969ecfdc47b2be06 to your computer and use it in GitHub Desktop.
Set woocommerce coupon to be available only for logged in users
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 | |
add_filter( 'woocommerce_coupon_is_valid', function( $is_valid, $coupon ) { | |
/** | |
* Selected coupons allowed for logged in users only | |
*/ | |
if ( in_array( $coupon->get_code() , ['loggedinonly', 'anothercoupontitle']) && ! is_user_logged_in() ) | |
{ | |
return false; | |
} | |
return $is_valid; | |
}, 100, 2 ); |
nicuvoicu
commented
Nov 8, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment