I would like to know how I can modify the code so that all transactions have a percentage surcharge and exclude France?
* Add a standard $ value surcharge to all transactions in cart / checkout
*/
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;
}
I found the code on the woocommerce site
Thank you for your response.
CodePudding user response:
Something like this based off how I am reading the code at least. Can't really test it but it seemed simple enaugh.
* Add a standard $ value surcharge to all transactions in cart / checkout
*/
add_action( 'woocommerce_cart_calculate_fees','wc_add_surcharge' );
function wc_add_surcharge() {
global $woocommerce;
if ( is_admin() && !defined( 'DOING_AJAX' ) ) return;
$county = ['FR']; //france
// change the $fee to set the surcharge to a value to suit
$fee = 1.00;
if ( !in_array( WC()->customer->get_shipping_country(), $county ) ){ //add the ! to exclude only countries in the list
$woocommerce->cart->add_fee( 'Surcharge', $fee, true, 'standard' );
}
}
CodePudding user response:
Thanks for your answer but it doesn't work for me! If I put a list of countries it would be:
if ( !in_array( WC()->customer->get_shipping_country(), $county ) ){ be,de,us,es,
$woocommerce->cart->add_fee( 'Surcharge', $fee, true, 'standard' );
The idea is to set up a surcharge for all other countries but exclude France. Thank you for your answer