I create custom checkout page with custom calculation. How i cant change total and tax_total via Ajax (or refresh page if need).
I create custom page for ajax request and set this code
$ss = new WC_Session_Handler();
$ss->set('tax_total',9999999);
$ss->save_data();
$ss->set('total',9999999);
$ss->save_data();
var_dump(WC());
On this page i can see my changes, but 'checkout page' nothing happens (even after refresh). How can I change the arbitrary total
or tax_total
.
Try to use
add_action('woocommerce_calculate_totals', array($this, 'calculate_totals'), 10, 1);
function calculate_totals($totals){
//your code
}
Also it shoul be tax_total
in cart object and you will can change it.
I've had problems getting other solutions to work for me, but at least for v.3.0.1, this worked great:
add_action('woocommerce_cart_total', 'calculate_totals', 10, 1);
function calculate_totals($wc_price){
$new_total = 0;
foreach ( WC()->cart->cart_contents as $key => $value ) {
//calculations here
}
return wc_price($new_total);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With