Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
537 B
2
Indexable
Never
add_filter( 'woocommerce_coupon_is_valid', function($is_valid, $coupon, $discount){

	$coupon_id = wc_get_coupon_id_by_code($coupon->get_code());
	$agent_id = get_post_meta($coupon_id, 'salesking_agent', true);

	if (!empty($agent_id)){
		if (intval($agent_id) !== 1){
			// if agent, only allow b2b custoemrs
			if (get_user_meta(get_current_user_id(),'b2bking_b2buser', true) !== 'yes'){
				if (intval(get_post_meta($coupon_id, 'coupon_amount', true)) == 100){
					$is_valid = false;
				}
			}
		}
	}
	return $is_valid;
	
}, 10, 3);
Leave a Comment