Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Created November 25, 2015 14:05
Show Gist options
  • Save greenhornet79/50d168e1aeea1063aa5b to your computer and use it in GitHub Desktop.
Save greenhornet79/50d168e1aeea1063aa5b to your computer and use it in GitHub Desktop.
Add percentage based fee to WooCommerce cart
<?php
add_action( 'woocommerce_cart_calculate_fees','endo_handling_fee' );
function endo_handling_fee() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$subtotal = $woocommerce->cart->subtotal;
$fee_percentage = 0.1; // 10 percent
$fee = number_format( round( $subtotal * $fee_percentage, 2 ), 2 ); // rounded to two decimal places to match currency formatting
$woocommerce->cart->add_fee( 'Handling', $fee, true, 'standard' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment