* WooCommerce Admin Settings Class
* @package WooCommerce\Admin
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
* WC_Admin_Settings Class.
class WC_Admin_Settings {
private static $settings = array();
private static $errors = array();
private static $messages = array();
* Include the settings page classes.
public static function get_settings_pages() {
if ( empty( self::$settings ) ) {
include_once __DIR__ . '/settings/class-wc-settings-page.php';
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-general.php';
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-products.php';
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-tax.php';
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-shipping.php';
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-payment-gateways.php';
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-accounts.php';
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-emails.php';
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-integrations.php';
if ( \Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'launch-your-store' ) ) {
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-site-visibility.php';
if ( FeaturesUtil::feature_is_enabled( 'point_of_sale' ) ) {
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-point-of-sale.php';
$settings[] = include_once __DIR__ . '/settings/class-wc-settings-advanced.php';
self::$settings = apply_filters( 'woocommerce_get_settings_pages', $settings );
if ( function_exists( 'get_current_screen' ) ) {
$screen = get_current_screen();
if ( 'woocommerce_page_wc-settings' === $screen->id ) {
$screen->remove_help_tabs();
// Reset settings when features that affect settings are toggled.
add_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( __CLASS__, 'reset_settings_pages_on_feature_change' ), 10, 2 );
* Reset settings when features that affect settings are toggled.
* @param string $feature_id The feature ID.
* @param bool $is_enabled Whether the feature is enabled.
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
public static function reset_settings_pages_on_feature_change( $feature_id, $is_enabled ) {
if ( 'point_of_sale' === $feature_id && $is_enabled ) {
self::$settings = array();
self::get_settings_pages();
public static function save() {
check_admin_referer( 'woocommerce-settings' );
do_action( 'woocommerce_settings_save_' . $current_tab );
do_action( 'woocommerce_update_options_' . $current_tab );
do_action( 'woocommerce_update_options' );
self::add_message( __( 'Your settings have been saved.', 'woocommerce' ) );
self::check_download_folder_protection();
// Clear any unwanted data and flush rules.
update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
WC()->query->init_query_vars();
WC()->query->add_endpoints();
do_action( 'woocommerce_settings_saved' );
* @param string $text Message.
public static function add_message( $text ) {
self::$messages[] = $text;
* @param string $text Message.
public static function add_error( $text ) {
* Output messages + errors.
public static function show_messages() {
if ( count( self::$errors ) > 0 ) {
foreach ( self::$errors as $error ) {
echo '<div id="message" class="error inline"><p><strong>' . esc_html( $error ) . '</strong></p></div>';
} elseif ( count( self::$messages ) > 0 ) {
foreach ( self::$messages as $message ) {
echo '<div id="message" class="updated inline"><p><strong>' . esc_html( $message ) . '</strong></p></div>';
* Handles the display of the main woocommerce settings page in admin.
public static function output() {
global $current_section, $current_tab;
$suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
do_action( 'woocommerce_settings_start' );
wp_enqueue_script( 'woocommerce_settings', WC()->plugin_url() . '/assets/js/admin/settings' . $suffix . '.js', array( 'jquery', 'wp-util', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'selectWoo' ), WC()->version, true );
'woocommerce_settings_params',
'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'woocommerce' ),
'i18n_moved_up' => __( 'Item moved up', 'woocommerce' ),
'i18n_moved_down' => __( 'Item moved down', 'woocommerce' ),
'i18n_no_specific_countries_selected' => __( 'Selecting no country / region to sell to prevents from completing the checkout. Continue anyway?', 'woocommerce' ),
// Get tabs for the settings page.
$tabs = apply_filters( 'woocommerce_settings_tabs_array', array() );
include __DIR__ . '/views/html-admin-settings.php';
* Get a setting from the settings API.
* @param string $option_name Option name.
* @param mixed $default Default value.
public static function get_option( $option_name, $default = '' ) {
if ( strstr( $option_name, '[' ) ) {
parse_str( $option_name, $option_array );
// Option name is first key.
$option_name = current( array_keys( $option_array ) );
$option_values = get_option( $option_name, '' );
$key = key( $option_array[ $option_name ] );
if ( isset( $option_values[ $key ] ) ) {
$option_value = $option_values[ $key ];
$option_value = get_option( $option_name, null );
if ( is_array( $option_value ) ) {
$option_value = wp_unslash( $option_value );
} elseif ( ! is_null( $option_value ) ) {
$option_value = stripslashes( $option_value );
return ( null === $option_value ) ? $default : $option_value;
* Loops through the woocommerce options array and outputs each field.
* @param array[] $options Opens array to output.
public static function output_fields( $options ) {
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) {
if ( ! isset( $value['id'] ) ) {
// The 'field_name' key can be used when it is useful to specify an input field name that is different
// from the input field ID. We use the key 'field_name' because 'name' is already in use for a different
if ( ! isset( $value['field_name'] ) ) {
$value['field_name'] = $value['id'];
if ( ! isset( $value['title'] ) ) {
$value['title'] = isset( $value['name'] ) ? $value['name'] : '';
if ( ! isset( $value['class'] ) ) {
if ( ! isset( $value['css'] ) ) {
if ( ! isset( $value['default'] ) ) {
if ( ! isset( $value['desc'] ) ) {
if ( ! isset( $value['desc_tip'] ) ) {
$value['desc_tip'] = false;
if ( ! isset( $value['placeholder'] ) ) {
$value['placeholder'] = '';
if ( ! isset( $value['row_class'] ) ) {
$value['row_class'] = '';
if ( ! empty( $value['row_class'] ) && substr( $value['row_class'], 0, 16 ) !== 'wc-settings-row-' ) {
$value['row_class'] = 'wc-settings-row-' . $value['row_class'];
if ( ! isset( $value['suffix'] ) ) {
if ( ! isset( $value['value'] ) ) {
$value['value'] = self::get_option( $value['id'], $value['default'] );
// Custom attribute handling.
$custom_attributes = array();
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
$field_description = self::get_field_description( $value );
$description = $field_description['description'];
$tooltip_html = $field_description['tooltip_html'];
switch ( $value['type'] ) {
if ( ! empty( $value['title'] ) ) {
echo '<h2>' . esc_html( $value['title'] ) . '</h2>';
if ( ! empty( $value['desc'] ) ) {
echo '<div id="' . esc_attr( sanitize_title( $value['id'] ) ) . '-description">';
echo wp_kses_post( wpautop( wptexturize( $value['desc'] ) ) );
echo '<table class="form-table">' . "\n\n";
if ( ! empty( $value['id'] ) ) {
do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) );
?><tr class="<?php echo esc_attr( $value['row_class'] ); ?>">
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?></th>
<td style="<?php echo esc_attr( $value['css'] ); ?>">
echo wp_kses_post( wpautop( wptexturize( $value['text'] ) ) );
if ( ! empty( $value['id'] ) ) {
do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_end' );
if ( ! empty( $value['id'] ) ) {
do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_after' );
// Standard text inputs and subtypes like 'number'.
$option_value = $value['value'];
<tr class="<?php echo esc_attr( $value['row_class'] ); ?>">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; // WPCS: XSS ok. ?></label>
<td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
name="<?php echo esc_attr( $value['field_name'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
type="<?php echo esc_attr( $value['type'] ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>"
value="<?php echo esc_attr( $option_value ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); // WPCS: XSS ok. ?>
/><?php echo esc_html( $value['suffix'] ); ?> <?php echo $description; // WPCS: XSS ok. ?>
$option_value = $value['value'];
<tr class="<?php echo esc_attr( $value['row_class'] ); ?>">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; // WPCS: XSS ok. ?></label>
<td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">‎
<span class="colorpickpreview" style="background: <?php echo esc_attr( $option_value ); ?>"> </span>
name="<?php echo esc_attr( $value['field_name'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>"
value="<?php echo esc_attr( $option_value ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>colorpick"
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); // WPCS: XSS ok. ?>
/>‎ <?php echo $description; // WPCS: XSS ok. ?>
<div id="colorPickerDiv_<?php echo esc_attr( $value['id'] ); ?>" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>
$option_value = $value['value'];
$show_desc_at_end = $value['desc_at_end'] ?? false;
<tr class="<?php echo esc_attr( $value['row_class'] ); ?>">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; // WPCS: XSS ok. ?></label>
<td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
if ( ! $show_desc_at_end ) {
echo wp_kses_post( $description );
name="<?php echo esc_attr( $value['field_name'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); // WPCS: XSS ok. ?>
><?php echo esc_textarea( $option_value ); // WPCS: XSS ok. ?></textarea>
if ( $show_desc_at_end ) {
echo wp_kses_post( $description );
$option_value = $value['value'];
<tr class="<?php echo esc_attr( $value['row_class'] ); ?>">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; // WPCS: XSS ok. ?></label>
<td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
name="<?php echo esc_attr( $value['field_name'] ); ?><?php echo ( 'multiselect' === $value['type'] ) ? '[]' : ''; ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); // WPCS: XSS ok. ?>
<?php echo 'multiselect' === $value['type'] ? 'multiple="multiple"' : ''; ?>
foreach ( $value['options'] as $key => $val ) {
<option value="<?php echo esc_attr( $key ); ?>"
if ( is_array( $option_value ) ) {
selected( in_array( (string) $key, $option_value, true ), true );
selected( $option_value, (string) $key );
><?php echo esc_html( $val ); ?></option>
</select> <?php echo $description; // WPCS: XSS ok. ?>
$option_value = $value['value'];
$disabled_values = $value['disabled'] ?? array();
$show_desc_at_end = $value['desc_at_end'] ?? false;
<tr class="<?php echo esc_attr( $value['row_class'] ); ?>">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; // WPCS: XSS ok. ?></label>
<td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
if ( ! $show_desc_at_end ) {