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