From d04746c9a5f7d6312cbc6802ee81dacd9c0562ea Mon Sep 17 00:00:00 2001 From: dwindown Date: Sun, 9 Nov 2025 00:42:51 +0700 Subject: [PATCH] fix: Update BOTH database tables for shipping method enabled status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FINAL FIX: WooCommerce stores enabled in TWO places! Discovery: - wp_options: woocommerce_flat_rate_X_settings["enabled"] - wp_woocommerce_shipping_zone_methods: is_enabled column - We were only updating wp_options - WooCommerce admin reads from zone_methods table - Checkout reads from zone_methods table too! Solution: ✅ Update wp_options (for settings) ✅ Update zone_methods table (for WooCommerce admin & checkout) ✅ Clear all caches ✅ Update in-memory property SQL Update: UPDATE wp_woocommerce_shipping_zone_methods SET is_enabled = 1/0 WHERE instance_id = X Now both sources stay in sync: ✅ SPA reads correct state ✅ WooCommerce admin shows correct state ✅ Checkout shows correct shipping options ✅ Everything works! This is the same pattern WooCommerce uses internally. --- includes/Api/ShippingController.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/includes/Api/ShippingController.php b/includes/Api/ShippingController.php index eb90ef9..b59eac8 100644 --- a/includes/Api/ShippingController.php +++ b/includes/Api/ShippingController.php @@ -277,16 +277,29 @@ class ShippingController extends WP_REST_Controller { // Debug: Log new state error_log( sprintf( '[WooNooW] New enabled value: %s', $new_enabled_value ) ); - // Save to database + // Save to database (wp_options table) $saved = update_option( $option_key, $current_settings, 'yes' ); error_log( sprintf( '[WooNooW] update_option(%s) returned: %s', $option_key, $saved ? 'true' : 'false' ) ); - // CRITICAL: Clear the zone's method cache so it reloads from DB + // CRITICAL: Also update the zone_methods table (where WooCommerce admin reads from) + global $wpdb; + $table_name = $wpdb->prefix . 'woocommerce_shipping_zone_methods'; + $updated = $wpdb->update( + $table_name, + array( 'is_enabled' => $enabled ? 1 : 0 ), + array( 'instance_id' => $instance_id ), + array( '%d' ), + array( '%d' ) + ); + error_log( sprintf( '[WooNooW] Updated zone_methods table: %s rows affected', $updated !== false ? $updated : 'ERROR' ) ); + + // Clear the zone's method cache so it reloads from DB delete_transient( 'wc_shipping_method_count' ); wp_cache_delete( 'shipping_zones', 'woocommerce' ); wp_cache_delete( $zone_id, 'shipping_zones' ); + \WC_Cache_Helper::get_transient_version( 'shipping', true ); - // Also update the in-memory property so WooCommerce sees it immediately + // Also update the in-memory property $method->enabled = $new_enabled_value; // Fire action hook for other plugins/code