Automattic\WooCommerce\Admin\Features

LaunchYourStore::save_site_visibility_options()publicWC 1.0

Save values submitted from WooCommerce -> Settings -> General.

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

Хуков нет.

Возвращает

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

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

$LaunchYourStore = new LaunchYourStore();
$LaunchYourStore->save_site_visibility_options();

Код LaunchYourStore::save_site_visibility_options() WC 9.7.1

public function save_site_visibility_options() {
	$nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
	if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'woocommerce-settings' ) ) {
		return;
	}

	// options to allowed update and their allowed values.
	$options = array(
		'woocommerce_coming_soon'      => array( 'yes', 'no' ),
		'woocommerce_store_pages_only' => array( 'yes', 'no' ),
		'woocommerce_private_link'     => array( 'yes', 'no' ),
	);

	$event_data = array();

	foreach ( $options as $name => $allowed_values ) {
		$current_value = get_option( $name, 'not set' );
		$new_value     = $current_value;

		if ( isset( $_POST[ $name ] ) ) {
			$input_value = sanitize_text_field( wp_unslash( $_POST[ $name ] ) );

			// no-op if input value is invalid.
			if ( in_array( $input_value, $allowed_values, true ) ) {
				update_option( $name, $input_value );
				$new_value = $input_value;

				// log the transition if there is one.
				if ( $current_value !== $new_value ) {
					$enabled_or_disabled              = 'yes' === $new_value ? 'enabled' : 'disabled';
					$event_data[ $name . '_toggled' ] = $enabled_or_disabled;
				}
			}
		}
		$event_data[ $name ] = $new_value;
	}
	wc_admin_record_tracks_event( 'site_visibility_saved', $event_data );
}