I'm trying to add a percentage based fee from Woocommerce subtotal in both cart and checkout. However, have this fee made up with a 5% surcharge of subtotal 20% tax of the 5% surcharge.
- Subtotal: £100
- Surcharge: £6 (<- £5 (5%) £1 Tax Surchange (20%)
I have managed to add the 5% percentage based fee of Subtotal. However, how do you add the 20% of $surcharge on top?
Also, will this type of change be effective for emails too? (As well as cart / checkout) is
Any advice would be appreciated.
Thanks in advance.
add_action( 'woocommerce_cart_calculate_fees','custom_adminfee_surcharge' );
function custom_adminfee_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$percentage = 0.05 * .20;
$surcharge = ( $woocommerce->cart->subtotal $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );
}
CodePudding user response:
This should be 5% of the subtotal then 20% of that 5%...
add_action( 'woocommerce_cart_calculate_fees','custom_adminfee_surcharge' );
function custom_adminfee_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$percentage = ( $woocommerce->cart->subtotal $woocommerce->cart->shipping_total ) * 0.05;
$surcharge = $percentage * 0.20;
$total_charges = $percentage $surcharge;
$woocommerce->cart->add_fee( 'Surcharge', $total_charges, true, '' );
}