Это возможно с этими 2 шагами:
1) Добавить уникальный купон с:
- В общих настройках> Тип = Фиксированная скидка на продукт
- В общих настройках> Сумма =
30
- В Ограничениях на использование> Продукты ==> установите желаемый продукт (s)
2) Добавьте этот код (где вы будете устанавливать код своего купона в функции (в нижнем регистре)):
add_filter( 'woocommerce_coupon_get_discount_amount', 'custom_coupon_get_discount_amount', 10, 5 );
function custom_coupon_get_discount_amount( $rounded_discount, $discounting_amount, $cart_item, $single, $coupon ){
## ---- Your settings ---- ##
// Related coupons codes to be defined in this array (you can set many)
$coupon_codes = array('30perqty');
## ------ The code ------- ##
if ( $coupon->is_type('fixed_product') && in_array( $coupon->get_code(), $coupon_codes ) && $cart_item['quantity'] > 1 ) {
if( in_array( $cart_item['product_id'], $coupon->get_product_ids() ) ){
$discount = (float) $coupon->get_amount() * (int) $cart_item['quantity'];
$round = round( min( $discount, $discounting_amount ), wc_get_rounding_precision() );
}
}
return $rounded_discount;
}
Код помещается в файл function.php вашей активной дочерней темы (или активной темы). Проверено и работает.