Automattic\WooCommerce\Internal\StockNotifications

StockSyncController::store_admin_notice │ private │ WC 1.0

Store the admin notice for the current user.

Runs once per request on shutdown, so a request that restocks several products (for example, a CSV import batch) writes once and lists all of them. Pending IDs from earlier requests are kept, so the notice covers every product restocked since the user last loaded an admin page.

Only store managers get a notice: a restock made by another user (for example, through an admin-ajax action from the storefront or a logged-out request) stores nothing.

Method of the class: StockSyncController{}

No Hooks.

Returns

void. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->store_admin_notice(): void;

StockSyncController::store_admin_notice() code WC 11.3.0

private function store_admin_notice(): void {
	$product_ids              = array_keys( $this->notice_product_ids );
	$this->notice_product_ids = array();

	if ( empty( $product_ids ) || ! is_admin() || ! get_current_user_id() || ! current_user_can( 'manage_woocommerce' ) ) {
		return;
	}

	try {
		$transient_key = $this->get_notice_transient_key();
		$pending_ids   = array_filter( array_map( 'absint', (array) get_transient( $transient_key ) ) );

		set_transient( $transient_key, array_values( array_unique( array_merge( $pending_ids, $product_ids ) ) ), DAY_IN_SECONDS );
	} catch ( \Throwable $e ) {
		$this->logger->error(
			sprintf( 'StockSyncController: Failed to store the restock admin notice: %s', $e->getMessage() ),
			array( 'source' => 'wc-customer-stock-notifications' )
		);
	}
}