Skip to content

Instantly share code, notes, and snippets.

@MindyPostoff
Created December 31, 2015 19:39
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 MindyPostoff/35d0cc3c3f3572960ccb to your computer and use it in GitHub Desktop.
Save MindyPostoff/35d0cc3c3f3572960ccb to your computer and use it in GitHub Desktop.
Add Surcharge to Cart
/**
* Add a 1% surcharge to your cart / checkout
* change the $percentage to set the surcharge to a value to suit
* Uses the WooCommerce fees API
*
* Add to theme functions.php
*/
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
$percentage = 0.01;
$surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percentage;
$cart->add_fee( 'Surcharge', $surcharge, true, '' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment