Skip to content

Instantly share code, notes, and snippets.

@luiseduardobraschi
Created June 7, 2019 02:37
Show Gist options
  • Save luiseduardobraschi/a07f024ae34eb49b377b16745ffe0d6c to your computer and use it in GitHub Desktop.
Save luiseduardobraschi/a07f024ae34eb49b377b16745ffe0d6c to your computer and use it in GitHub Desktop.
Allow coupon only for customers who already have placed orders.
<?php
add_filter('woocommerce_coupon_is_valid', 'wcbr_coupon_is_valid', 10, 2);
function wcbr_coupon_is_valid( $valid, $coupon ) {
global $woocommerce;
$customer = $woocommerce->customer;
if ( wc_get_customer_order_count( $customer->get_id() ) < 1 ) {
return false;
}
return $valid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment