So, I am working with my custom plugin in which I need to get zip code or postcode on woocommerce checkout page and add my additional price and be done with the payment. I tried using AJAX, which get the zip code and add my price into it and update the price.
/** Here my AJAX Call **/ global $woocommerce; //$additional_amount is coming dynamically via an external API $additional_amount = 5.00; // can vary depending upon zip code number_format((float)$additional_amount, 2, '.', ''); $woocommerce->cart->set_total($woocommerce->cart->total + $additional_amount);
Then I send this total to my AJAX call back like below:
$arr['amount'] = $woocommerce->cart->get_total(); echo json_encode($arr);exit();
It shows me updated price but when I do payment process using stripe or any other payment gateway, it charges my the old price.
I also tried it this way
$fee = 5.00; $woocommerce->cart->add_fee( 'Handling', $fee, true, 'standard' );
But it also does not work. Is there a way to do add my additional price into checkout amount using AJAX or any other way. I am using Wordpress 5.4 and Woocommerce version 4.0.1