Automattic\WooCommerce\Internal\StockNotifications\Admin

SettingsController::add_my_account_endpoint_setting │ public │ WC 1.0

Add the stock notifications endpoint setting to Settings > Advanced > Account endpoints.

Sits with the core account endpoints rather than in the feature's own section, since everything that reads it is the endpoint plumbing core owns. Unlike the core entries it only shows while the feature is enabled, because this controller loads with the feature.

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

Хуков нет.

Возвращает

array. New settings.

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

$SettingsController = new SettingsController();
$SettingsController->add_my_account_endpoint_setting( $settings, $section_id );
$settings(массив) (обязательный)
Original settings.
$section_id(строка) (обязательный)
Settings section identifier.

Код SettingsController::add_my_account_endpoint_setting() WC 11.2.2

public function add_my_account_endpoint_setting( $settings, $section_id ) {

	if ( ! is_array( $settings ) ) {
		return $settings;
	}

	if ( '' !== $section_id ) {
		return $settings;
	}

	$setting = array(
		'title'    => __( 'Stock notifications', 'woocommerce' ),
		'desc'     => __( 'Endpoint for the "My account → Stock notifications" page.', 'woocommerce' ),
		'id'       => MyAccountEndpoint::ENDPOINT_OPTION,
		'type'     => 'text',
		'default'  => MyAccountEndpoint::ENDPOINT,
		'desc_tip' => true,
	);

	// Slot it right after Downloads so it sits with the other list endpoints,
	// otherwise before Logout so Logout stays last, otherwise at the end of the group.
	$position = 0;
	foreach ( array_values( $settings ) as $index => $field ) {
		if ( ! is_array( $field ) || ! isset( $field['id'] ) ) {
			continue;
		}
		if ( 'woocommerce_myaccount_downloads_endpoint' === $field['id'] ) {
			$position = $index + 1;
			break;
		}
		if ( 'woocommerce_logout_endpoint' === $field['id'] || ( 'account_endpoint_options' === $field['id'] && 'sectionend' === ( $field['type'] ?? '' ) ) ) {
			$position = $index;
			break;
		}
	}

	if ( 0 === $position ) {
		return $settings;
	}

	array_splice( $settings, $position, 0, array( $setting ) );

	return $settings;
}