Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MinaPansuriya/5d5c14b3eb68080f3f00d80520a625ee to your computer and use it in GitHub Desktop.
Save MinaPansuriya/5d5c14b3eb68080f3f00d80520a625ee to your computer and use it in GitHub Desktop.
/**
* @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