Last active
October 24, 2016 15:23
-
-
Save luancmaia/39b5333e63376473d1a31319a36852d7 to your computer and use it in GitHub Desktop.
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
//Just include it to your functions.php | |
// VALIDATE YOUR COUPON CODE FOR THE FIRST ORDER ONLY | |
add_filter( 'woocommerce_coupon_is_valid', 'woocommerce_coupon_first_order', 10, 2 ); | |
function woocommerce_coupon_first_order( $true, $instance ) { | |
if ( ( $instance->code != 'COUPONCODE' ) || ! is_user_logged_in() ) return $true; | |
$customer_orders = get_posts( array( | |
'meta_key' => '_customer_user', | |
'meta_value' => get_current_user_id(), | |
'post_type' => 'shop_order', | |
'numberposts'=> -1 | |
) ); | |
$true = count( $customer_orders ) > 0 ? false : $true; | |
return $true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment