Automattic\WooCommerce\Blocks\BlockTypes
AddToWishlistButton::is_initial_in_wishlist
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.
Метод класса: AddToWishlistButton{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->is_initial_in_wishlist( $items, $product ): bool;
- $items(массив) (обязательный)
- .
- $product(WC_Product) (обязательный)
- The product being viewed.
Код AddToWishlistButton::is_initial_in_wishlist() AddToWishlistButton::is initial in wishlist WC 11.0.1
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;
}