woogists
3/11/2018 - 4:07 PM

[WooCommerce Core] Add a standard $ value surcharge to all transactions

[Frontend Snippets][Add a surcharge to cart and checkout] Add a standard $ value surcharge to all transactions

add_action( 'woocommerce_cart_calculate_fees','wc_add_surcharge' ); 
function wc_add_surcharge() { 
global $woocommerce; 

if ( is_admin() && ! defined( 'DOING_AJAX' ) ) 
return;

$county = array('US');
// change the $fee to set the surcharge to a value to suit
$fee = 1.00;

if ( in_array( WC()->customer->get_shipping_country(), $county ) ) : 
    $woocommerce->cart->add_fee( 'Surcharge', $fee, true, 'standard' );  
endif;
}