Reputation: 309
Is there any JavaScript or PHP solution to recalculate and replace Subtotal of mini cart based on available price values on page reload?
Currently I have two different currencies, for example Euro & Lira, when I add some items to cart in Euro currency the subtotal is correct but when I reload page in Lira currency the Subtotal value for added items is obviously wrong, so I need to recalculate subtotal for available items on page load and replace it with the returning subtotal value by Woocommerce.
Can you please help me to do it?
Update: I tried a tweak but still does not work! By default mini-cart.php use widget hook to display total or subtotal:
do_action( 'woocommerce_widget_shopping_cart_total' );
I tried this code instead but still on page load with a different currency it does not display correct subtotal (it returns a value similar to subtoal of other currency):
<p class="woocommerce-mini-cart__total total">
<?php
$subtotal_txt = isset($options['sc-subtotal-text']) ? $options['sc-subtotal-text']: __("Subtotal:",'side-cart-woocommerce');
?>
<span><?php esc_attr_e($subtotal_txt,'side-cart-woocommerce') ?></span>
<?php echo WC()->cart->get_cart_subtotal(); ?>
</p>
Should I add a JS or Ajax fragments to have a correct subtotal on every page load?
Upvotes: 1
Views: 2932
Reputation: 309
Answer: The important point is calling calculate_totals()
, It seems like a bug. Anyway you may use this code instead:
<p class="woocommerce-mini-cart__total total">
<?php
WC()->cart->calculate_totals();
do_action( 'woocommerce_widget_shopping_cart_total' );
?>
</p>
Upvotes: 1