我正在创建一个新的折扣规则到购物车小计,如下所示,但随后应用的优惠券不会应用于新的小计。
如何在购物车中设置新小计并将优惠券应用于新小计?
$subtotal = WC()->cart->subtotal;
if (($subtotal > 2399)&&($subtotal <= 3200))
{
$eligible = ((15/100)*$subtotal);
}
else if (($subtotal > 3200)&&($subtotal <= 3500))
{
$eligible = ((18/100)*$subtotal);
}
else if (($subtotal > 3500)&&($subtotal < 3500))
{
$eligible = ((20/100)*$subtotal);
}
$newsubtotal = $subtotal - $eligible;
if ( $amount = WC()->cart->get_coupon_discount_amount( $coupon->code, WC()->cart->display_cart_ex_tax ) )
{
//i need to get discount amount based on new subtotal
$discount_html = '-' . wc_price( $amount );
}
else
{
$discount_html = '';
}