Last active
September 7, 2023 22:17
-
-
Save chuckmo/9c2a57f64cf60ee0d9d3 to your computer and use it in GitHub Desktop.
Disable WooCommerce's Shipping Rates Cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// updated per harisrozak: | |
add_filter('woocommerce_checkout_update_order_review', 'clear_wc_shipping_rates_cache'); | |
function clear_wc_shipping_rates_cache(){ | |
$packages = WC()->cart->get_shipping_packages(); | |
foreach ($packages as $key => $value) { | |
$shipping_session = "shipping_for_package_$key"; | |
unset(WC()->session->$shipping_session); | |
} | |
} |
After research for 2 days, i got this solution, i think this more cleaner:
add_filter('woocommerce_checkout_update_order_review', 'clear_wc_shipping_rates_cache');
function clear_wc_shipping_rates_cache(){
$packages = WC()->cart->get_shipping_packages();
foreach ($packages as $key => $value) {
$shipping_session = "shipping_for_package_$key";
unset(WC()->session->$shipping_session);
}
}
👍 harisrozak ! you're my new best friend :-)
@harisrozak the best. Thank you!
Hello
I tried to apply @harisrozak snippet or @DeyviJam snippet too but it's not working for me on last version of woo. Do you know how i can disable the woocommerce shipping cache plz?
The @harisrozak code must be hooked to the woocommerce_checkout_update_order_review action, not filter.
thank you! @harisrozak
Thanks @harisrozak!
Another method:
add_action('woocommerce_checkout_update_order_review', 'clear_wc_shipping_rates_cache');
function clear_wc_shipping_rates_cache(){
WC_Cache_Helper::get_transient_version( 'shipping', true );
}
After research for 2 days, i got this solution, i think this more cleaner:
add_filter('woocommerce_checkout_update_order_review', 'clear_wc_shipping_rates_cache'); function clear_wc_shipping_rates_cache(){ $packages = WC()->cart->get_shipping_packages(); foreach ($packages as $key => $value) { $shipping_session = "shipping_for_package_$key"; unset(WC()->session->$shipping_session); } }
This is working like a charm.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At some point, they edited the
option_name
, also storing it in a serialized array, so something like this should be used now: