diff --git a/includes/Api/ShippingController.php b/includes/Api/ShippingController.php index 97b0528..18b4b9e 100644 --- a/includes/Api/ShippingController.php +++ b/includes/Api/ShippingController.php @@ -222,36 +222,37 @@ class ShippingController extends WP_REST_Controller { ); } - // Get all shipping methods for this zone - $shipping_methods = $zone->get_shipping_methods(); + // CRITICAL: Get ALL shipping methods (both enabled and disabled) + $shipping_methods = $zone->get_shipping_methods( false ); $method_found = false; - $option_key = ''; foreach ( $shipping_methods as $method ) { if ( $method->instance_id == $instance_id ) { $method_found = true; - $option_key = $method->get_instance_option_key(); // Debug logging error_log( sprintf( '[WooNooW] Toggling shipping method %s (instance %d) to %s', $method->id, $instance_id, $enabled ? 'enabled' : 'disabled' ) ); - // Get current settings and merge with new enabled status + // Get current settings $method->init_instance_settings(); $current_settings = $method->instance_settings; - $new_settings = array_merge( $current_settings, array( 'enabled' => $enabled ? 'yes' : 'no' ) ); - // Debug: Log current and new settings + // Update enabled status + $method->instance_settings['enabled'] = $enabled ? 'yes' : 'no'; + + // Debug: Log settings change error_log( sprintf( '[WooNooW] Current enabled: %s, New enabled: %s', isset( $current_settings['enabled'] ) ? $current_settings['enabled'] : 'not set', - $new_settings['enabled'] + $method->instance_settings['enabled'] ) ); - // Update settings directly - $method->instance_settings = $new_settings; + // Save to database + $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' ) ); - // Save to database using WooCommerce's method - $saved = update_option( $option_key, $new_settings, 'yes' ); - error_log( sprintf( '[WooNooW] update_option returned: %s', $saved ? 'true' : 'false' ) ); + // Fire action hook for other plugins/code + do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $zone_id, $enabled ); break; }