Define a % surcharge by delivery country with WooCommerce

themify landing review

Similar to the 1% surcharge snippet, this will add a basic surcharge however only applied to specific countries. Keep in mind that you can reverse this and exclude from surcharge list with a simple little change of in_array to !in_array and you are good to go. We have the wonderful people at WooCommerce to thank for this snippet you can view the original here.

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, '' );

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!