# This is post #1 of 31 in the challenge “Mastering WooCommerce”
This snippet mostly explained how you can add a 5% surcharge to WooCommerce cart / checkout based on conditions.
Option 1 (Add 5% surcharge for all) :
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge_all' ); function woocommerce_custom_surcharge_all() { global $woocommerce; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $percentage = 0.05; //change this value for surcharge percentage $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage; $woocommerce->cart->add_fee( 'Surcharge (5%)', $surcharge, true, 'standard' ); }
Option 2 (Add 5% surcharge based on country) :
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge_country' ); function woocommerce_custom_surcharge_country() { global $woocommerce; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $county = array('US'); $percentage = 0.05; //change this value to update % / activity 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 (5%) *US Only', $surcharge, true, 'standard' ); endif; }
Pingback: Challenge List : 31 Ways to Customize WooCommerce | Terry Tsang : PHP Developer and Wordpress Consultant
is there any way to add surcharge to only paypal?
total = cart total * 3.9% + 0.5
Looks Great! Is there a way to apply x dollars surcharge based on quantity with a minimum amount. Sample: Apply $5 surcharge fee per quantity for all purchases under $100.00 (i.e. 10 items with sub-total of 99.00 will activate 10×5=$50 )