Skip to content

Instantly share code, notes, and snippets.

@luiseduardobraschi
Created September 11, 2019 16:35
Show Gist options
  • Save luiseduardobraschi/1a25f9dd01a4b8033e7d1ee30d0ba29b to your computer and use it in GitHub Desktop.
Save luiseduardobraschi/1a25f9dd01a4b8033e7d1ee30d0ba29b to your computer and use it in GitHub Desktop.
[WooCommerce BR] Restrict coupon from being used bt its author
<?php
add_filter('woocommerce_coupon_is_valid', 'wcbr_coupon_is_valid', 10, 2);
function wcbr_coupon_is_valid( $valid, $coupon ) {
global $woocommerce;
$customer_id = $woocommerce->customer->get_id();
$coupon_author_id = get_post_field( 'post_author', $coupon->get_id() );
if ( $customer_id === $coupon_author_id ) {
return false;
}
return $valid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment