cyberfly
cyberfly

Reputation: 5848

Woocommerce tax calculation with cart custom fees

I have 3 custom fees added to my cart using this code, and it works fine

function woo_add_cart_fee() {

global $woocommerce;

$admin_fees = get_option( 'admin_fees', 10 );
$stamp_duty = get_option( 'stamp_duty', 10 );
$refundable_deposit = get_option( 'refundable_deposit', 10 );

$woocommerce->cart->add_fee( __('Admin Fees', 'woocommerce'), $admin_fees );
$woocommerce->cart->add_fee( __('Stamp Duty', 'woocommerce'), $stamp_duty );
$woocommerce->cart->add_fee( __('Refundable Deposit', 'woocommerce'), $refundable_deposit );

}

add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );

Right now I need to charge GST Tax 6% on the cart total. However what happens now is that only my product got charge GST 6% tax, while the 3 custom fees is not included. Refer to the image below:

enter image description here

How to fix it?

Thanks

Upvotes: 1

Views: 2385

Answers (1)

cyberfly
cyberfly

Reputation: 5848

Update:

Ah silly me, it turns out there is tax argument for add_fee function

Woocommerce WC_Cart documentation

So the full working code is

function woo_add_cart_fee() {

global $woocommerce;

$admin_fees = get_option( 'admin_fees', 10 );
$stamp_duty = get_option( 'stamp_duty', 10 );
$refundable_deposit = get_option( 'refundable_deposit', 10 );

$woocommerce->cart->add_fee( __('Admin Fees', 'woocommerce'), $admin_fees, TRUE, '');
$woocommerce->cart->add_fee( __('Stamp Duty', 'woocommerce'), $stamp_duty, TRUE, '' );
$woocommerce->cart->add_fee( __('Refundable Deposit', 'woocommerce'), $refundable_deposit, TRUE, '' );

}

add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );

Thanks

Upvotes: 2

Related Questions