Automattic\WooCommerce\Internal\StockNotifications\Frontend
MyAccountEndpoint::register_menu_item
Inject the menu entry between "Downloads" and "Addresses" if present, otherwise append.
Method of the class: MyAccountEndpoint{}
No Hooks.
Returns
array<string, string>.
Usage
$MyAccountEndpoint = new MyAccountEndpoint(); $MyAccountEndpoint->register_menu_item( $items, $endpoints );
- $items(array<string, string>) (required)
- The current menu items.
- $endpoints(array<string, string>) (required)
- The resolved endpoint slugs (unused, kept for filter signature).
MyAccountEndpoint::register_menu_item() MyAccountEndpoint::register menu item code WC 11.2.1
public function register_menu_item( $items, $endpoints ) {
// Avoid parameter not used PHPCS errors.
unset( $endpoints );
if ( ! is_array( $items ) ) {
return $items;
}
// A blank endpoint slug disables the endpoint, so the link would 404.
if ( '' === self::get_endpoint_slug() ) {
return $items;
}
$new_item = array(
self::ENDPOINT => __( 'Stock notifications', 'woocommerce' ),
);
// Try to slot it in right after Downloads so it sits with the other lists.
if ( isset( $items['downloads'] ) ) {
$position = array_search( 'downloads', array_keys( $items ), true );
if ( false !== $position ) {
return array_slice( $items, 0, $position + 1, true )
+ $new_item
+ array_slice( $items, $position + 1, null, true );
}
}
// Otherwise insert before customer-logout so "Log out" stays last.
if ( isset( $items['customer-logout'] ) ) {
$position = array_search( 'customer-logout', array_keys( $items ), true );
if ( false !== $position ) {
return array_slice( $items, 0, $position, true )
+ $new_item
+ array_slice( $items, $position, null, true );
}
}
return $items + $new_item;
}