Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* @Title: WooCommerce Charge additional amount if Cart Quantity exceed given amount
* @Author: Mina Pansuriya
* @Website: http://minapansuriya.com
*/
add_action( 'woocommerce_cart_calculate_fees', 'pbs_woo_charge_additional_fees_for_x_no_of_products' );
function pbs_woo_charge_additional_fees_for_x_no_of_products(){
global $woocommerce;
$cart_content = $woocommerce->cart->get_cart();
$qty = 0;
foreach($cart_content as $key => $value){
$qty += $value['quantity'];
}
$extraCostQtyLimit = 10;
if($qty > $extraCostQtyLimit)
{
$additionalCost = 10;
$woocommerce->cart->add_fee('Extra Charges (No. of Products > '.$extraCostQtyLimit.')', $additionalCost);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment