admin管理员组文章数量:1431912
I'm creating a shipping method where the customer can choose a time for the delivery to happen. This choice can be made on product page, cart and checkout. When chosen, it updates a session value with ajax.
The problem however is that I need to re-calculate shipping on cart and checkout if the time is changed, but woocommerce is not calculating shipping unless items are added or removed from the cart.
It wont even recalculate if i refresh the page, I have to manually change the content of the cart for it to fire.
Any suggestions?
I'm creating a shipping method where the customer can choose a time for the delivery to happen. This choice can be made on product page, cart and checkout. When chosen, it updates a session value with ajax.
The problem however is that I need to re-calculate shipping on cart and checkout if the time is changed, but woocommerce is not calculating shipping unless items are added or removed from the cart.
It wont even recalculate if i refresh the page, I have to manually change the content of the cart for it to fire.
Any suggestions?
Share Improve this question asked Aug 8, 2018 at 21:13 JorgenJorgen 1411 silver badge5 bronze badges 1- 1 Could you provide the related code for the shipping method, or at least a link to it… Thank you. – LoicTheAztec Commented Apr 10, 2019 at 1:20
2 Answers
Reset to default 2I also have the same issue when I created a shipping method and what I did is on my function for the ajax call I add something just to have an update on the cart:
global $woocommerce;
$packages = $woocommerce->cart->get_shipping_packages();
foreach( $packages as $package_key => $package ) {
$session_key = 'shipping_for_package_'.$package_key;
$stored_rates = WC()->session->__unset( $session_key );
}
Please try adding this where needed:
WC()->cart->calculate_shipping();
WC()->cart->calculate_totals();
This is how WooCommerce handles it in its own Ajax calls.
I found this in WC_Ajax::update_order_review()
(class-wc-ajax.php:354).
本文标签: Calling calculateshipping() with ajax in woocommerce
版权声明:本文标题:Calling calculate_shipping() with ajax in woocommerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745583763a2664773.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论