Arka
Arka

Reputation: 25

Get woocommerce tax percentage by address programmatically

I am building Android app for an woocommerce store.

The website has tax rates defined for different shipping areas.
Here are some sample rates defined in woocommerce tax section:

I need to show the tax calculated for a shipping area in customer's cart.

So, if a customer enters shipping address, I will do an ajax call to my API backend in the same server, get the tax rate (6%, 7% or 7.5% depending on location), and update the cart data displayed in the app.

I have searched the forum but not getting an answer on how to get the tax percentage for a given area.

Upvotes: 1

Views: 945

Answers (1)

rajat.gite
rajat.gite

Reputation: 446

Brother can you try this. logical method inside condition you can do your own code and logic's

/* Remove tax from cart for FOB orders */
function change_tax_for_fob( $cart ) {
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping = $chosen_methods[0]; 
    if($chosen_shipping =='FOB') {
        // Do your Code
        //$cart->remove_taxes();
    }
    return $cart;
}
add_action( 'woocommerce_calculate_totals', 'change_tax_for_fob' );

OR

add_action( 'woocommerce_review_order_before_submit','custom_review_order_before_submit');
function custom_review_order_before_submit() {
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping = $chosen_methods[0];
    if( "FOB" == $chosen_shipping ) {
        <!-- Do Your Code -->
    }
}

Upvotes: 0

Related Questions