Based on WooCommerce Cart Quantity Base Discount answer code, I apply a discount from xx products on shopping cart with the following:
add_action( 'woocommerce_cart_calculate_fees','wc_cart_quantity_discount', 10, 1 );
function wc_cart_quantity_discount( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
## -------------- DEFINIG VARIABLES ------------- ##
$discount = 0;
$cart_item_count = $cart_object->get_cart_contents_count();
$cart_total_excl_tax = $cart_object->subtotal_ex_tax;
## ----------- CONDITIONAL PERCENTAGE ----------- ##
if( $cart_item_count <= 17 )
$percent = 0;
elseif( $cart_item_count >= 18 && $cart_item_count <= 120 )
$percent = 10;
## ------------------ CALCULATION ---------------- ##
$discount -= ($cart_total_excl_tax / 100) * $percent;
## ---- APPLYING CALCULATED DISCOUNT TAXABLE ---- ##
if( $percent > 0 )
$cart_object->add_fee( __( 'Remise sur la quantité 10%', 'woocommerce' ), $discount, true);
}
But I would like to manage the discount from quantity for each product.
Do you have any tips for that?