Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('woocommerce_apply_individual_use_coupon', function($keep_coupon, $the_coupon, $applied_coupons) {
- $vendor_wise_coupons = [];
- if( $the_coupon->get_individual_use() ) {
- $coupon_id = $the_coupon->get_id();
- $coupon_vendor = wcfm_get_vendor_id_by_post( $coupon_id );
- if( $coupon_vendor ) {
- foreach ( $applied_coupons as $applied_coupon ) {
- $this_coupon = new WC_Coupon($applied_coupon);
- $this_coupon_vendor = wcfm_get_vendor_id_by_post( $this_coupon->get_id() );
- if( $this_coupon_vendor !== $coupon_vendor) {
- if( !$this_coupon->get_individual_use()) {
- $vendor_wise_coupons[$this_coupon_vendor][] = $applied_coupon;
- } else {
- $vendor_wise_coupons[$this_coupon_vendor] = [$applied_coupon];
- }
- }
- }
- foreach($vendor_wise_coupons as $vendor_id => $coupons) {
- $keep_coupon = array_merge($keep_coupon, $coupons);
- }
- }
- }
- return array_unique( $keep_coupon );
- }, 10, 3);
- add_filter('woocommerce_apply_with_individual_use_coupon', function($is_allowed, $the_coupon, $individual_coupon, $applied_coupons) {
- $coupon_id = $the_coupon->get_id();
- $coupon_vendor = wcfm_get_vendor_id_by_post( $coupon_id );
- $individual_use_coupon_vendor = wcfm_get_vendor_id_by_post( $individual_coupon->get_id() );
- if( $coupon_vendor && $coupon_vendor !== $individual_use_coupon_vendor ) {
- return true;
- }
- return $is_allowed;
- }, 10, 4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement