Ii've code for checking quantity of goods in cart, and then it makes a discount based on quantity. How can I make additional check on price for goods below 500 (for these goods, discount should be 0).
The following code is based on WooCommerce Cart quantity based discount answer:
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;
/*foreach( $cart_object->get_cart() as $cart_item_key => $cart_item ) {
$cart_item = $cart_object->get_cart_contents_count();
}*/
// Assign each product's price to its cart item key (to be used again later)
## ----------- CONDITIONAL PERCENTAGE ----------- ##
if( $cart_item_count <= 1 )
$percent = 5;
elseif( $cart_item_count <= 2 )
$percent = 10;
elseif( $cart_item_count <= 3 )
$percent = 15;
elseif( $cart_item_count <= 4 )
$percent = 20;
elseif( $cart_item_count >= 5 )
$percent = 25;
else {
$percent = 0;
}
## ------------------ CALCULATION ---------------- ##
$discount -= ($cart_total_excl_tax / 100) * $percent;
## ---- APPLYING CALCULATED DISCOUNT TAXABLE ---- ##
if( $percent > 0 )
$cart_object->add_fee( __( "Quantity discount $percent%", "woocommerce" ), $discount, true);
}
Should be checking for quantity and price below, for example, 500 (the discount should be 0). For another goods with condition: price is higher 500 and the corresponding quantity, its own discount:
1 - 5%
2 - 10%
3 - 15%
etc.