From a1779ebbdf68a8ce34b79446c1a4a0d80f544a19 Mon Sep 17 00:00:00 2001 From: dwindown Date: Sun, 9 Nov 2025 00:50:00 +0700 Subject: [PATCH] chore: Remove debug logs from shipping toggle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleaned up all debug logging now that toggle works perfectly. Removed: - Backend error_log statements - Frontend console.log statements - Kept only essential code Result: Clean, production-ready code ✅ --- admin-spa/src/routes/Settings/Shipping.tsx | 13 +----- includes/Api/ShippingController.php | 53 +++------------------- 2 files changed, 7 insertions(+), 59 deletions(-) diff --git a/admin-spa/src/routes/Settings/Shipping.tsx b/admin-spa/src/routes/Settings/Shipping.tsx index 62e9563..ea49c12 100644 --- a/admin-spa/src/routes/Settings/Shipping.tsx +++ b/admin-spa/src/routes/Settings/Shipping.tsx @@ -38,18 +38,7 @@ export default function ShippingPage() { // Fetch shipping zones from WooCommerce const { data: zones = [], isLoading, refetch } = useQuery({ queryKey: ['shipping-zones'], - queryFn: async () => { - const data = await api.get('/settings/shipping/zones'); - console.log('[Shipping] Fetched zones:', data); - // Log each zone's methods - data.forEach((zone: any) => { - console.log(`[Shipping] Zone "${zone.name}" (ID: ${zone.id}):`, zone.rates); - zone.rates?.forEach((rate: any) => { - console.log(` - ${rate.name}: enabled=${rate.enabled}`); - }); - }); - return data; - }, + queryFn: () => api.get('/settings/shipping/zones'), staleTime: 5 * 60 * 1000, // 5 minutes }); diff --git a/includes/Api/ShippingController.php b/includes/Api/ShippingController.php index b59eac8..1dfc3b3 100644 --- a/includes/Api/ShippingController.php +++ b/includes/Api/ShippingController.php @@ -99,24 +99,9 @@ class ShippingController extends WP_REST_Controller { foreach ( $shipping_methods as $method ) { // Get fresh settings from database - $method->init_instance_settings(); - - // CRITICAL: The enabled property comes from init_settings, not init_instance_settings - // We need to check the actual settings property $settings = get_option( $method->get_instance_option_key(), array() ); $is_enabled = isset( $settings['enabled'] ) && $settings['enabled'] === 'yes'; - // Debug: Check ALL sources of enabled status - error_log( sprintf( - '[WooNooW] Zone %d Method %s (instance %d): $method->enabled = "%s", instance_settings["enabled"] = "%s", DB option["enabled"] = "%s"', - $zone_data['id'], - $method->id, - $method->instance_id, - isset( $method->enabled ) ? $method->enabled : 'NOT SET', - isset( $method->instance_settings['enabled'] ) ? $method->instance_settings['enabled'] : 'NOT SET', - isset( $settings['enabled'] ) ? $settings['enabled'] : 'NOT SET' - ) ); - $rate = array( 'id' => $method->id . ':' . $method->instance_id, 'instance_id' => $method->instance_id, @@ -158,22 +143,9 @@ class ShippingController extends WP_REST_Controller { foreach ( $shipping_methods as $method ) { // Get fresh settings from database - $method->init_instance_settings(); - - // CRITICAL: Read directly from database option $settings = get_option( $method->get_instance_option_key(), array() ); $is_enabled = isset( $settings['enabled'] ) && $settings['enabled'] === 'yes'; - // Debug: Check ALL sources of enabled status - error_log( sprintf( - '[WooNooW] Zone 0 (Rest of World) Method %s (instance %d): $method->enabled = "%s", instance_settings["enabled"] = "%s", DB option["enabled"] = "%s"', - $method->id, - $method->instance_id, - isset( $method->enabled ) ? $method->enabled : 'NOT SET', - isset( $method->instance_settings['enabled'] ) ? $method->instance_settings['enabled'] : 'NOT SET', - isset( $settings['enabled'] ) ? $settings['enabled'] : 'NOT SET' - ) ); - $rate = array( 'id' => $method->id . ':' . $method->instance_id, 'instance_id' => $method->instance_id, @@ -258,40 +230,27 @@ class ShippingController extends WP_REST_Controller { if ( $method->instance_id == $instance_id ) { $method_found = true; - // Debug logging - error_log( sprintf( '[WooNooW] Toggling shipping method %s (instance %d) to %s', $method->id, $instance_id, $enabled ? 'enabled' : 'disabled' ) ); - - // Get current settings DIRECTLY from database (not from cached instance_settings) + // Get current settings from database $option_key = $method->get_instance_option_key(); $current_settings = get_option( $option_key, array() ); - - // Debug: Log current state from database - error_log( sprintf( '[WooNooW] Current DB option[enabled]: %s', - isset( $current_settings['enabled'] ) ? $current_settings['enabled'] : 'not set' - ) ); - // Update the enabled value in the settings array + // Update the enabled value $new_enabled_value = $enabled ? 'yes' : 'no'; $current_settings['enabled'] = $new_enabled_value; - // Debug: Log new state - error_log( sprintf( '[WooNooW] New enabled value: %s', $new_enabled_value ) ); - - // 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' ) ); + // Save to wp_options table + update_option( $option_key, $current_settings, 'yes' ); - // CRITICAL: Also update the zone_methods table (where WooCommerce admin reads from) + // Also update the zone_methods table (where WooCommerce admin reads from) global $wpdb; $table_name = $wpdb->prefix . 'woocommerce_shipping_zone_methods'; - $updated = $wpdb->update( + $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' );