我实际上想要一个最大折扣为xxx $的百分比优惠券系统。
这是我在WordPress中用于WooCommerce插件的代码,但无法正常工作。
add_filter( 'woocommerce_coupon_get_discount_amount', 'woocommerce_coupon_get_discount_amount', 20, 5 );
function woocommerce_coupon_get_discount_amount( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
$max_discount = get_post_meta( $coupon->get_id(), '_max_discount', true );
if ( is_numeric( $max_discount ) && ( $max_discount > 0 ) ..... && ! is_null( $cart_item ) && WC()->cart->subtotal_ex_tax ) {
$cart_item_qty = is_null( $cart_item ) ? 1 : $cart_item['quantity'];
if ( wc_prices_include_tax() ) {
$discount_percent = ( wc_get_price_including_tax( $cart_item['data'] ) * $cart_item_qty ) / WC()->cart->subtotal;
} else {
$discount_percent = ( wc_get_price_excluding_tax( $cart_item['data'] ) * $cart_item_qty ) / WC()->cart->subtotal_ex_tax;
}
$_discount = ( $max_discount * $discount_percent ) / $cart_item_qty;
$discount = min( $_discount, $discount );
}
return $discount;
}
您能帮我解决一下吗?