Automattic\WooCommerce\Blocks\BlockTypes\OrderConfirmation
DownloadsWrapper::store_has_downloadable_products
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.
Returns
true|false.
Usage
// protected - for code of main (parent) or child class $result = $this->store_has_downloadable_products();
DownloadsWrapper::store_has_downloadable_products() DownloadsWrapper::store has downloadable products code WC 10.9.1
protected function store_has_downloadable_products() {
global $wpdb;
if ( get_option( 'woocommerce_product_lookup_table_is_generating' ) ) {
// The underlying SQL is slower than querying `wc_product_meta_lookup`, so caching is used for performance.
$has_downloadable_products = wp_cache_get( 'woocommerce_has_downloadable_products', 'woocommerce' );
if ( false === $has_downloadable_products ) {
$has_downloadable_products = (bool) $wpdb->get_var(
"SELECT posts.ID
FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->postmeta} as postmeta ON posts.ID = postmeta.post_id
WHERE
postmeta.meta_key = '_downloadable'
AND postmeta.meta_value = 'yes'
AND posts.post_type = 'product'
AND posts.post_status = 'publish'
LIMIT 1"
);
$has_downloadable_products = $has_downloadable_products ? 'yes' : 'no';
wp_cache_set( 'woocommerce_has_downloadable_products', $has_downloadable_products, 'woocommerce', HOUR_IN_SECONDS );
}
$has_downloadable_products = 'yes' === $has_downloadable_products;
} else {
$has_downloadable_products = (bool) $wpdb->get_var(
"SELECT product_id FROM {$wpdb->wc_product_meta_lookup} WHERE downloadable = 1 LIMIT 1",
);
}
return $has_downloadable_products;
}