WC_Settings_Tracking::track_setting_change
Add WooCommerce option to a list of updated options.
Method of the class: WC_Settings_Tracking{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Settings_Tracking = new WC_Settings_Tracking(); $WC_Settings_Tracking->track_setting_change( $option_name, $old_value, $new_value );
- $option_name(string) (required)
- Option being updated.
- $old_value(mixed) (required)
- Old value of option.
- $new_value(mixed) (required)
- New value of option.
WC_Settings_Tracking::track_setting_change() WC Settings Tracking::track setting change code WC 10.6.2
public function track_setting_change( $option_name, $old_value, $new_value ) {
// Make sure this is a WooCommerce option.
if ( ! in_array( $option_name, $this->allowed_options, true ) ) {
return;
}
// Check to make sure the new value is truly different.
// `woocommerce_price_num_decimals` tends to trigger this
// because form values aren't coerced (e.g. '2' vs. 2).
if (
is_scalar( $old_value ) &&
is_scalar( $new_value ) &&
(string) $old_value === (string) $new_value
) {
return;
}
if ( in_array( $option_name, $this->dropdown_menu_options, true ) ) {
$this->modified_options[ $option_name ] = $new_value;
} elseif ( in_array( $new_value, array( 'yes', 'no' ), true ) && in_array( $old_value, array( 'yes', 'no' ), true ) ) {
// Save toggled options.
$option_state = 'yes' === $new_value ? 'enabled' : 'disabled';
$this->toggled_options[ $option_state ][] = $option_name;
}
$this->updated_options[] = $option_name;
}