Automattic\WooCommerce\Blocks\BlockTypes

AddToWishlistButton::is_initial_in_wishlistprivateWC 1.0

Whether the current product (or its parent, for a variable parent with no selection yet) is already in the prefetched wishlist. For variable products the SSR star is always empty — we can't know which variation the shopper will pick before JS hydrates.

Method of the class: AddToWishlistButton{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->is_initial_in_wishlist( $items, $product ): bool;
$items(array) (required)
.
$product(WC_Product) (required)
The product being viewed.

AddToWishlistButton::is_initial_in_wishlist() code WC 10.9.4

private function is_initial_in_wishlist( array $items, \WC_Product $product ): bool {
	if ( $product->is_type( 'variable' ) ) {
		return false;
	}
	$product_id = $product->get_id();
	foreach ( $items as $item ) {
		if ( isset( $item['id'] ) && (int) $item['id'] === $product_id ) {
			return true;
		}
	}
	return false;
}