Skip to content

Instantly share code, notes, and snippets.

@luancmaia
Last active October 24, 2016 15:23
Show Gist options
  • Save luancmaia/39b5333e63376473d1a31319a36852d7 to your computer and use it in GitHub Desktop.
Save luancmaia/39b5333e63376473d1a31319a36852d7 to your computer and use it in GitHub Desktop.
//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