I wish to take away coupon just for gadgets that has already low cost and that’s bigger than added coupon low cost.
I’ve code that provides common worth to cost if coupon is added.
However want additionally code that removes low cost for that already discounted product inside else clause inside under code.
operate add_custom_price( $cart_object) {
world $woocommerce;
if ( is_admin() && ! outlined( 'DOING_AJAX' ) )
return;
$coupon = False;
if ($coupons = WC()->cart->get_applied_coupons() == False )
$coupon = False;
else {
foreach ( WC()->cart->get_applied_coupons() as $code ) {
$coupons1 = new WC_Coupon( $code );
if ($code === 'randomCoupon' && $coupons1->get_discount_type() == '%'){
$coupon = True;
}
}
}
if ($coupon == True)
foreach ( $cart_object->get_cart() as $cart_item )
{
$worth = $cart_item['data']->get_regular_price();
$priceSales = $cart_item['data']->get_sale_price();
$discountPercentage = 0;
if(is_numeric($priceSales)) {
$discountPercentage = ($priceSales * 100) / $worth;
}
if($discountPercentage < $couponPercentage) {
$cart_item['data']->set_price( $worth );
} else {
// Right here I would like an answer that removes coupon for that product
}
}
}
Is that type of resolution potential?