Skip to content

Instantly share code, notes, and snippets.

Last active November 30, 2021 10:39
What would you like to do?
[Frontend Snippets][Add a surcharge to cart and checkout] Add a surcharge based on the delivery country
* Add a 1% surcharge to your cart / checkout based on delivery country
* Taxes, shipping costs and order subtotal are all included in the surcharge amount
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
$county = array('US');
$percentage = 0.01;
if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ) :
$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );
Copy link

Good morning @woogists,

I'm currently using this code with an additional plugin ( to show Canadian users the CAD $ pricing and then convert back to USD with a -0.25 percentage. I know that the tax is calculated on the Subtotal of the items in the cart, but I was wondering if there's a way to apply (or modify) this code to have the original tax shown on the Cart & Checkout Page?

My main goal is to show everything in CAD $ pricing on the Cart/Checkout review section and then have the USD $ pricing pushed shown as the Final Total (and sent to See the attached screenshot.

I thought maybe there might be a way to re-add the 'discounted' percentage back into the Tax, but I'm not sure if WooCommerce has a hook to manipulate the tax calculation.

CAD   USD Review Checkout

Any help would be much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment