Bulk discount
<?php
function add_custom_bulk_fee( ) {
global $woocommerce;
$subtotal = $woocommerce->cart->subtotal;
$total_packages = 0;
foreach($woocommerce->cart->get_cart() as $cart_item) {
if($cart_item['data']->is_type('yith_bundle')) {
$total_packages += $cart_item['quantity'];
}
}
foreach($woocommerce->cart->get_cart() as $cart_item) {
if($cart_item['data']->is_type('yith_bundle')) {
$items = $total_packages;
if($items >= 25 && $items < 50) {
$discountPercentage = 3;
$discount = ($subtotal / 100 * $discountPercentage);
$woocommerce->cart->add_fee( sprintf(esc_html__( 'U heeft %1$s pakketten. Er is %2$s% korting verrekend', 'sandersgifts' ), $items, $discountPercentage ), -$discount);
}
if($items >= 50 && $items < 100) {
$discountPercentage = 6;
$discount = ($subtotal / 100 * $discountPercentage);
$woocommerce->cart->add_fee( sprintf(esc_html__( 'U heeft %1$s pakketten. Er is %2$s% korting verrekend', 'sandersgifts' ), $items, $discountPercentage ), -$discount);
}
if($items >= 100 && $items < 250) {
$discountPercentage = 9;
$discount = ($subtotal / 100 * $discountPercentage);
$woocommerce->cart->add_fee( sprintf(esc_html__( 'U heeft %1$s pakketten. Er is %2$s% korting verrekend', 'sandersgifts' ), $items, $discountPercentage ), -$discount);
}
if($items >= 250 && $items < 500) {
$discountPercentage = 12;
$discount = ($subtotal / 100 * $discountPercentage);
$woocommerce->cart->add_fee( sprintf(esc_html__( 'U heeft %1$s pakketten. Er is %2$s% korting verrekend', 'sandersgifts' ), $items, $discountPercentage ), -$discount);
}
if($items >= 500) {
$discountPercentage = 15;
$discount = ($subtotal / 100 * $discountPercentage);
$woocommerce->cart->add_fee( sprintf(esc_html__( 'U heeft %1$s pakketten. Er is %2$s% korting verrekend', 'sandersgifts' ), $items, $discountPercentage ), -$discount);
}
}
}
return $cart;
}
add_action('woocommerce_cart_calculate_fees' , 'add_custom_bulk_fee');
add_action('woocommerce_cart_totals_get_fees_from_cart_taxes', function() {
return [];
}, 10, 3);