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 sugi1119/348599102057578a58dcd0b6ace59954 to your computer and use it in GitHub Desktop.
Save sugi1119/348599102057578a58dcd0b6ace59954 to your computer and use it in GitHub Desktop.
WooCommerce: Add extra fee when product total exceed certain amount
add_action( 'woocommerce_cart_calculate_fees', 'loc_woo_charge_additional_fee_for_nr_of_products' );
function loc_woo_charge_additional_fee_for_nr_of_products(){
global $woocommerce;
$cart_content = $woocommerce->cart->get_cart();
$qty = 0;
foreach($cart_content as $key => $value){
$qty += $value['quantity'];
}
$extraCostQtyLimit = 500;
if($qty > $extraCostQtyLimit)
{
$additionalCost = 100;
$woocommerce->cart->add_fee('YOUR TEXT HERE '.$extraCostQtyLimit.' YOUR TEXT HERE', $additionalCost);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment