Skip to content

Instantly share code, notes, and snippets.

@woogists
Last active May 27, 2024 15:13
Show Gist options
  • Save woogists/271654709e1d27648546e83253c1a813 to your computer and use it in GitHub Desktop.
Save woogists/271654709e1d27648546e83253c1a813 to your computer and use it in GitHub Desktop.
Conditional shipping rate cache invalidation
<?php
/**
* This implementation will disable the shipping rate cache.
* To conditionally disable the cache, replace `wp_rand()` with a conditional value.
* Changing the conditional value will invalidate the cache.
* Example: A hidden form field or a query string parameter.
*/
function wc_shipping_rate_cache_invalidation( $packages ) {
foreach ( $packages as &$package ) {
$package['rate_cache'] = wp_rand();
}
return $packages;
}
add_filter( 'woocommerce_cart_shipping_packages', 'wc_shipping_rate_cache_invalidation', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment