WC_Settings_Tracking::track_setting_change()publicWC 1.0

Add WooCommerce option to a list of updated options.

Метод класса: WC_Settings_Tracking{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WC_Settings_Tracking = new WC_Settings_Tracking();
$WC_Settings_Tracking->track_setting_change( $option_name, $old_value, $new_value );
$option_name(строка) (обязательный)
Option being updated.
$old_value(разное) (обязательный)
Old value of option.
$new_value(разное) (обязательный)
New value of option.

Код WC_Settings_Tracking::track_setting_change() WC 8.7.0

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;
}