diff --git a/includes/Api/ShippingController.php b/includes/Api/ShippingController.php index 8f84bc6..85fc526 100644 --- a/includes/Api/ShippingController.php +++ b/includes/Api/ShippingController.php @@ -265,9 +265,8 @@ class ShippingController extends WP_REST_Controller { isset( $method->instance_settings['enabled'] ) ? $method->instance_settings['enabled'] : 'not set' ) ); - // Update BOTH the property AND the settings + // Update the settings array with new enabled value $new_enabled_value = $enabled ? 'yes' : 'no'; - $method->enabled = $new_enabled_value; $method->instance_settings['enabled'] = $new_enabled_value; // Debug: Log new state @@ -277,6 +276,14 @@ class ShippingController extends WP_REST_Controller { $option_key = $method->get_instance_option_key(); $saved = update_option( $option_key, $method->instance_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 + delete_transient( 'wc_shipping_method_count' ); + wp_cache_delete( 'shipping_zones', 'woocommerce' ); + wp_cache_delete( $zone_id, 'shipping_zones' ); + + // Also update the in-memory property so WooCommerce sees it immediately + $method->enabled = $new_enabled_value; // Fire action hook for other plugins/code do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $zone_id, $enabled );