Automattic\WooCommerce\Blocks\BlockTypes\OrderConfirmation

DownloadsWrapper::store_has_downloadable_products()protectedWC 1.0

See if the store has a downloadable product. This controls if we bother to show a preview in the editor.

Method of the class: DownloadsWrapper{}

No Hooks.

Return

true|false.

Usage

// protected - for code of main (parent) or child class
$result = $this->store_has_downloadable_products();

DownloadsWrapper::store_has_downloadable_products() code WC 8.9.0

protected function store_has_downloadable_products() {
	$has_downloadable_product = get_transient( 'wc_blocks_has_downloadable_product', false );

	if ( false === $has_downloadable_product ) {
		$product_ids              = get_posts(
			array(
				'post_type'   => 'product',
				'numberposts' => 1,
				'post_status' => 'publish',
				'fields'      => 'ids',
				// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
				'meta_query'  => array(
					array(
						'key'     => '_downloadable',
						'value'   => 'yes',
						'compare' => '=',
					),
				),
			)
		);
		$has_downloadable_product = ! empty( $product_ids );
		set_transient( 'wc_blocks_has_downloadable_product', $has_downloadable_product ? '1' : '0', MONTH_IN_SECONDS );
	}

	return (bool) $has_downloadable_product;
}