How to Add a % surcharge to your cart / checkout with WooCommerce

If you are a WooCommerce user this great snippet will add a 1% surcharge to your cart on checkout. You can easily change the $percentage variable to adjust the surcharge percent and you are good to go.
( click code to copy )wordpress snippet : PHP
<>
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' ); function woocommerce_custom_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, '' ); }