Automattic\WooCommerce\Internal\StockNotifications\Frontend
MyAccountEndpoint::render_endpoint
Render the endpoint template.
Hooked to woocommerce_account_stock-notifications_endpoint, mirroring how woocommerce_account_downloads and woocommerce_account_orders hook up.
Method of the class: MyAccountEndpoint{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$MyAccountEndpoint = new MyAccountEndpoint(); $MyAccountEndpoint->render_endpoint( $current_page ): void;
- $current_page(string|int)
- The current page number passed by WC (the value captured from the rewrite endpoint, e.g.
2for/my-account/stock-notifications/2/). Empty string when no page is in the URL.
Default:1
MyAccountEndpoint::render_endpoint() MyAccountEndpoint::render endpoint code WC 11.2.1
public function render_endpoint( $current_page = 1 ): void {
$current_page = max( 1, (int) $current_page );
/**
* Filter the per-page count for the My Account stock-notifications table.
*
* @since 11.2.0
*
* @param int $per_page Number of notifications shown per page. Default {@see self::DEFAULT_PER_PAGE}.
*/
$per_page = (int) apply_filters( 'woocommerce_account_customer_stock_notifications_per_page', self::DEFAULT_PER_PAGE );
$per_page = max( 1, $per_page );
/**
* Filter how many pending (awaiting confirmation) notifications the My Account
* stock-notifications tab lists above the active table.
*
* The pending table is not paginated, so this is a hard cap.
*
* @since 11.2.0
*
* @param int $limit Maximum number of pending notifications shown. Default {@see self::DEFAULT_PER_PAGE}.
*/
$pending_limit = (int) apply_filters( 'woocommerce_account_customer_stock_notifications_pending_limit', self::DEFAULT_PER_PAGE );
$pending_limit = max( 1, $pending_limit );
$pending = $this->get_current_user_pending_notifications( $pending_limit );
$page = $this->get_current_user_notifications_page( $current_page, $per_page );
// Both lists come from raw SQL selects, so nothing has primed the post cache
// for the products the rows render. Prime it once here instead of letting
// each row's wc_get_product() call issue its own query.
$product_ids = array_filter( array_map( static fn( $notification ) => (int) $notification->get_product_id(), array_merge( $pending, $page['notifications'] ) ) );
if ( $product_ids ) {
_prime_post_caches( array_values( array_unique( $product_ids ) ) );
}
\wc_get_template(
'myaccount/stock-notifications.php',
$this->view->get_template_args(
$pending,
$page['notifications'],
array(
'current_page' => $page['current_page'],
'total_pages' => $page['total_pages'],
'total_items' => $page['total_items'],
'per_page' => $per_page,
)
)
);
}