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.

Method of the class: SettingsController{}

No Hooks.

Returns

array. New settings.

Usage

$SettingsController = new SettingsController();
$SettingsController->add_my_account_endpoint_setting( $settings, $section_id );
$settings(array) (required)
Original settings.
$section_id(string) (required)
Settings section identifier.

SettingsController::add_my_account_endpoint_setting() code WC 11.3.0

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