Skip to content

Instantly share code, notes, and snippets.

@iMazed
Last active October 14, 2016 12:32
Show Gist options
  • Save iMazed/cf060c0a2b88bc8df7c47ea1f5a4308f to your computer and use it in GitHub Desktop.
Save iMazed/cf060c0a2b88bc8df7c47ea1f5a4308f to your computer and use it in GitHub Desktop.
Add a surcharge to your WooCommerce cart/checkout
<?php
/**
* Add a 3% surcharge to your cart / checkout
* change the $percentage to set the surcharge to a value to suit
*/
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$percentage = 0.03;
$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