fix: Update BOTH enabled sources when toggling
Root cause identified and fixed! Problem: - WooCommerce stores enabled in TWO places: 1. $method->enabled property (what admin displays) 2. $method->instance_settings["enabled"] (what we were updating) - We were only updating instance_settings, not the property - So toggle saved to DB but $method->enabled stayed "yes" Solution: ✅ Read from $method->enabled (correct source) ✅ Update BOTH $method->enabled AND instance_settings["enabled"] ✅ Save instance_settings to database ✅ Now both sources stay in sync Evidence from logs: - Before: $method->enabled = "yes", instance_settings = "no" (mismatch!) - Toggle was reading "no", trying to set "no" → no change - update_option returned false (no change detected) After this fix: ✅ Toggle reads correct current state ✅ Updates both property and settings ✅ Saves to database correctly ✅ WooCommerce admin and SPA stay in sync
This commit is contained in:
@@ -258,17 +258,21 @@ class ShippingController extends WP_REST_Controller {
|
||||
|
||||
// Get current settings
|
||||
$method->init_instance_settings();
|
||||
$current_settings = $method->instance_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',
|
||||
$method->instance_settings['enabled']
|
||||
|
||||
// Debug: Log current state from BOTH sources
|
||||
error_log( sprintf( '[WooNooW] Current $method->enabled: %s, instance_settings["enabled"]: %s',
|
||||
isset( $method->enabled ) ? $method->enabled : 'not set',
|
||||
isset( $method->instance_settings['enabled'] ) ? $method->instance_settings['enabled'] : 'not set'
|
||||
) );
|
||||
|
||||
// Update BOTH the property AND the settings
|
||||
$new_enabled_value = $enabled ? 'yes' : 'no';
|
||||
$method->enabled = $new_enabled_value;
|
||||
$method->instance_settings['enabled'] = $new_enabled_value;
|
||||
|
||||
// Debug: Log new state
|
||||
error_log( sprintf( '[WooNooW] New enabled value: %s', $new_enabled_value ) );
|
||||
|
||||
// Save to database
|
||||
$option_key = $method->get_instance_option_key();
|
||||
$saved = update_option( $option_key, $method->instance_settings, 'yes' );
|
||||
|
||||
Reference in New Issue
Block a user