Commit 830f38b44e4 for woocommerce
commit 830f38b44e4304c96163da031d363de3b780bf65
Author: Tung Du <dinhtungdu@gmail.com>
Date: Mon Apr 13 21:51:29 2026 +0700
Prevent shop rewrite corruption from WP-CLI and cron contexts (#64117)
diff --git a/plugins/woocommerce/changelog/fix-63954-skip-themes-flush-rewrite-rules b/plugins/woocommerce/changelog/fix-63954-skip-themes-flush-rewrite-rules
new file mode 100644
index 00000000000..ffecd3106e1
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-63954-skip-themes-flush-rewrite-rules
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Do not update theme support option or queue rewrite rule flush when running in WP-CLI or cron contexts, preventing hosts that run WP-CLI with --skip-themes from corrupting the shop page rewrite rules.
diff --git a/plugins/woocommerce/includes/class-wc-post-types.php b/plugins/woocommerce/includes/class-wc-post-types.php
index 3f4986a2269..7efed18e73a 100644
--- a/plugins/woocommerce/includes/class-wc-post-types.php
+++ b/plugins/woocommerce/includes/class-wc-post-types.php
@@ -341,9 +341,13 @@ class WC_Post_Types {
}
// If theme support changes, we may need to flush permalinks since some are changed based on this flag.
- $theme_support = wc_current_theme_supports_woocommerce_or_fse() ? 'yes' : 'no';
- if ( get_option( 'current_theme_supports_woocommerce' ) !== $theme_support && update_option( 'current_theme_supports_woocommerce', $theme_support ) ) {
- update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
+ // Skip this check in WP-CLI and cron contexts: themes may not be loaded (e.g. --skip-themes),
+ // which would incorrectly record theme support as "no" and corrupt rewrite rules on the frontend.
+ if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) && ! wp_doing_cron() ) {
+ $theme_support = wc_current_theme_supports_woocommerce_or_fse() ? 'yes' : 'no';
+ if ( get_option( 'current_theme_supports_woocommerce' ) !== $theme_support && update_option( 'current_theme_supports_woocommerce', $theme_support ) ) {
+ update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
+ }
}
register_post_type(