Automattic\WooCommerce\Internal\Caches

ProductCache::get │ public │ WC 10.5.0

Retrieve a cached product, and if no product is cached with the given id, try to get one via get_from_datastore callback and then cache it.

After retrieval, resets the clone mode to DUPLICATE to maintain backward compatibility for code that expects cloning to clear meta IDs.

Метод класса: ProductCache{}

Хуков нет.

Возвращает

WC_Product|null. Cached product, or null if it's not cached and can't be retrieved from datastore or via callback.

Использование

$ProductCache = new ProductCache();
$ProductCache->get( $id, $expiration, ?callable $get_from_datastore_callback ): ?WC_Product;
$id(int|строка) (обязательный)
The id of the product to retrieve.
$expiration(int)
Expiration of the cached data in seconds from the current time, used if a product is retrieved from datastore and cached.
По умолчанию: self::DEFAULT_EXPIRATION
?callable $get_from_datastore_callback
.
По умолчанию: null

Список изменений

С версии 10.5.0 Введена.

Код ProductCache::get() WC 11.2.2

public function get( $id, int $expiration = self::DEFAULT_EXPIRATION, ?callable $get_from_datastore_callback = null ): ?WC_Product {
	$id      = (int) $id;
	$product = parent::get( $id, $expiration, $get_from_datastore_callback );

	if ( $product instanceof WC_Product ) {
		$product->set_clone_mode( \WC_Data::CLONE_MODE_DUPLICATE );
		return $product;
	}

	return null;
}