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:
@@ -38,18 +38,7 @@ export default function ShippingPage() {
|
|||||||
// Fetch shipping zones from WooCommerce
|
// Fetch shipping zones from WooCommerce
|
||||||
const { data: zones = [], isLoading, refetch } = useQuery({
|
const { data: zones = [], isLoading, refetch } = useQuery({
|
||||||
queryKey: ['shipping-zones'],
|
queryKey: ['shipping-zones'],
|
||||||
queryFn: async () => {
|
queryFn: () => api.get('/settings/shipping/zones'),
|
||||||
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;
|
|
||||||
},
|
|
||||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -99,24 +99,9 @@ class ShippingController extends WP_REST_Controller {
|
|||||||
|
|
||||||
foreach ( $shipping_methods as $method ) {
|
foreach ( $shipping_methods as $method ) {
|
||||||
// Get fresh settings from database
|
// 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() );
|
$settings = get_option( $method->get_instance_option_key(), array() );
|
||||||
$is_enabled = isset( $settings['enabled'] ) && $settings['enabled'] === 'yes';
|
$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(
|
$rate = array(
|
||||||
'id' => $method->id . ':' . $method->instance_id,
|
'id' => $method->id . ':' . $method->instance_id,
|
||||||
'instance_id' => $method->instance_id,
|
'instance_id' => $method->instance_id,
|
||||||
@@ -158,22 +143,9 @@ class ShippingController extends WP_REST_Controller {
|
|||||||
|
|
||||||
foreach ( $shipping_methods as $method ) {
|
foreach ( $shipping_methods as $method ) {
|
||||||
// Get fresh settings from database
|
// Get fresh settings from database
|
||||||
$method->init_instance_settings();
|
|
||||||
|
|
||||||
// CRITICAL: Read directly from database option
|
|
||||||
$settings = get_option( $method->get_instance_option_key(), array() );
|
$settings = get_option( $method->get_instance_option_key(), array() );
|
||||||
$is_enabled = isset( $settings['enabled'] ) && $settings['enabled'] === 'yes';
|
$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(
|
$rate = array(
|
||||||
'id' => $method->id . ':' . $method->instance_id,
|
'id' => $method->id . ':' . $method->instance_id,
|
||||||
'instance_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 ) {
|
if ( $method->instance_id == $instance_id ) {
|
||||||
$method_found = true;
|
$method_found = true;
|
||||||
|
|
||||||
// Debug logging
|
// Get current settings from database
|
||||||
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)
|
|
||||||
$option_key = $method->get_instance_option_key();
|
$option_key = $method->get_instance_option_key();
|
||||||
$current_settings = get_option( $option_key, array() );
|
$current_settings = get_option( $option_key, array() );
|
||||||
|
|
||||||
// Debug: Log current state from database
|
// Update the enabled value
|
||||||
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
|
|
||||||
$new_enabled_value = $enabled ? 'yes' : 'no';
|
$new_enabled_value = $enabled ? 'yes' : 'no';
|
||||||
$current_settings['enabled'] = $new_enabled_value;
|
$current_settings['enabled'] = $new_enabled_value;
|
||||||
|
|
||||||
// Debug: Log new state
|
// Save to wp_options table
|
||||||
error_log( sprintf( '[WooNooW] New enabled value: %s', $new_enabled_value ) );
|
update_option( $option_key, $current_settings, 'yes' );
|
||||||
|
|
||||||
// Save to database (wp_options table)
|
// Also update the zone_methods table (where WooCommerce admin reads from)
|
||||||
$saved = update_option( $option_key, $current_settings, 'yes' );
|
|
||||||
error_log( sprintf( '[WooNooW] update_option(%s) returned: %s', $option_key, $saved ? 'true' : 'false' ) );
|
|
||||||
|
|
||||||
// CRITICAL: Also update the zone_methods table (where WooCommerce admin reads from)
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$table_name = $wpdb->prefix . 'woocommerce_shipping_zone_methods';
|
$table_name = $wpdb->prefix . 'woocommerce_shipping_zone_methods';
|
||||||
$updated = $wpdb->update(
|
$wpdb->update(
|
||||||
$table_name,
|
$table_name,
|
||||||
array( 'is_enabled' => $enabled ? 1 : 0 ),
|
array( 'is_enabled' => $enabled ? 1 : 0 ),
|
||||||
array( 'instance_id' => $instance_id ),
|
array( 'instance_id' => $instance_id ),
|
||||||
array( '%d' ),
|
array( '%d' ),
|
||||||
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
|
// Clear the zone's method cache so it reloads from DB
|
||||||
delete_transient( 'wc_shipping_method_count' );
|
delete_transient( 'wc_shipping_method_count' );
|
||||||
|
|||||||
Reference in New Issue
Block a user