chore: Remove debug logs from shipping toggle

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 
This commit is contained in:
dwindown
2025-11-09 00:50:00 +07:00
parent d04746c9a5
commit a1779ebbdf
2 changed files with 7 additions and 59 deletions

View File

@@ -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' );