Last active
May 27, 2024 15:13
-
-
Save woogists/271654709e1d27648546e83253c1a813 to your computer and use it in GitHub Desktop.
Conditional shipping rate cache invalidation
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
<?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