diff --git a/ordernumber_helper_woocommerce.php b/ordernumber_helper_woocommerce.php index d877bb7ee5e2a3542638909c46fe87d13bf7427b..479ab4f3540d2787e56113aca74143a406d7de37 100644 --- a/ordernumber_helper_woocommerce.php +++ b/ordernumber_helper_woocommerce.php @@ -100,6 +100,12 @@ class OrdernumberHelperWooCommerce extends OrdernumberHelper { } function getCounter($type, $format, $default=0) { + // the option is cached, so two orders at approximately the same time + // (one submitted while the other one is still processed) will get the + // same counter value from the cach, unless we explicitly erase the + // cache and force WP to look into the database for the current value + wp_cache_delete ('alloptions', 'options'); + wp_cache_delete (self::$ordernumber_counter_prefix.$type.'-'.$format, 'options'); return get_option (self::$ordernumber_counter_prefix.$type.'-'.$format, $default); } @@ -108,7 +114,7 @@ class OrdernumberHelperWooCommerce extends OrdernumberHelper { } function setCounter($type, $format, $value) { - return update_option(self::$ordernumber_counter_prefix.$type.'-'.$format, $value); + return update_option(self::$ordernumber_counter_prefix.$type.'-'.$format, $value, /*autoload=*/false); } function deleteCounter($type, $format) {