Ecommerce Shopify WordPress Discussion

Woocommerce Shipping Method cost does not add to order total with below code? How to Fix?

The below code I found on Stack works well to stop shipping calculations at add to cart and in the cart. Shipping calculations do work in checkout as they are supposed to but when a shipping method is selected it does not add the cost to the total. function filter_need_shipping($val) { // Check if we need to recalculate shipping if (!is_admin()) { $prevent_after_add = WC()->session->get('prevent_recalc_on_add_to_cart'); return $val && !$prevent_after_add; } return $val; } add_filter('woocommerce_cart_needs_shipping', 'filter_need_shipping'); function mark_cart_not_to_recalc() { // Mark the cart not to recalculate when adding items if (!is_admin()) { WC()->session->set('prevent_recalc_on_add_to_cart', true); } } add_action('woocommerce_before_calculate_totals', 'mark_cart_not_to_recalc'); // Unset the flag when proceeding to checkout add_action('woocommerce_checkout_init', 'unset_prevent_recalc_flag'); function unset_prevent_recalc_flag() { if (!is_admin()) { WC()->session->__unset('prevent_recalc_on_add_to_cart'); } } Any idea on how to fix it?
you can try it: function filter_need_shipping($val) { // Check if we need to recalculate shipping if (!is_admin()) { $prevent_after_add = WC()->session->get('prevent_recalc_on_add_to_cart'); return $val && !$prevent_after_add; } return $val; } add_filter('woocommerce_cart_needs_shipping', 'filter_need_shipping'); function mark_cart_not_to_recalc() { // Mark the cart not to recalculate when adding items if (!is_admin() && is_cart()) { WC()->session->set('prevent_recalc_on_add_to_cart', true); } } add_action('woocommerce_before_calculate_totals', 'mark_cart_not_to_recalc'); // Unset the flag when proceeding to checkout add_action('woocommerce_checkout_init', 'unset_prevent_recalc_flag'); function unset_prevent_recalc_flag() { if (!is_admin()) { WC()->session->__unset('prevent_recalc_on_add_to_cart'); } }

February 26, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.