Skip to content

Instantly share code, notes, and snippets.

@gnikolopoulos
Last active September 14, 2015 17:37
Show Gist options
  • Save gnikolopoulos/926c8790f38f1f9a0c46 to your computer and use it in GitHub Desktop.
Save gnikolopoulos/926c8790f38f1f9a0c46 to your computer and use it in GitHub Desktop.
[WooCommerce] Add surcharge to your cart / checkout
add_action( 'woocommerce_cart_calculate_fees','woocommerce_surcharge' );
function woocommerce_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$percentage = 0.01;
$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment