Home > Software engineering >  Woocommerce - displays price with tax, but charging without tax
Woocommerce - displays price with tax, but charging without tax

Time:12-04

I have a problem with wocommerce shop. I'm manually adding product to cart by below code:

WC()->cart->add_to_cart( $product_id, 1, 0, array(), array( 'misha_custom_price' => $my_custom_price ) );

In my functions.php I have added below code:

add_action( 'woocommerce_before_calculate_totals', 'rudr_custom_price_refresh' );

function rudr_custom_price_refresh( $cart_object ) {

    foreach ( $cart_object->get_cart() as $item ) {

        if( array_key_exists( 'misha_custom_price', $item ) ) {
            $item[ 'data' ]->set_price( $item[ 'misha_custom_price' ] );
        }
      
    }
    
}

On my checkout page, price is shown correctly, eg. 123$ (including 23$ as 23% VAT). But when I go to pay, I see price without tax (100$). Please help me. Thanks.

CodePudding user response:

I found a solution. I was using a plugin to manage checkout fields. I have hidden the "Coutry" field on the checkout page. This field must be visible for the tax to work properly.

  • Related