Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories

Synchronize::get_next_set_of_downloadable_products()privateWC 1.0

Queries for the next batch of downloadable products, applying logic to ensure we only fetch those that actually have downloadable files (a downloadable product can be created that does not have downloadable files and/or downloadable files can be removed from existing downloadable products).

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

Хуков нет.

Возвращает

Массив.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_next_set_of_downloadable_products(): array;

Код Synchronize::get_next_set_of_downloadable_products() WC 8.7.0

private function get_next_set_of_downloadable_products(): array {
	$query_filter = function ( array $query ): array {
		$query['meta_query'][] = array(
			'key'     => '_downloadable_files',
			'compare' => 'EXISTS',
		);

		return $query;
	};

	$page = (int) get_option( self::SYNC_TASK_PAGE, 1 );
	add_filter( 'woocommerce_product_data_store_cpt_get_products_query', $query_filter );

	$products = wc_get_products(
		array(
			'limit'    => self::SYNC_TASK_BATCH_SIZE,
			'page'     => $page,
			'paginate' => true,
		)
	);

	remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', $query_filter );
	$progress = $products->max_num_pages > 0 ? (int) ( ( $page / $products->max_num_pages ) * 100 ) : 1;
	update_option( self::SYNC_TASK_PAGE, $page + 1 );
	update_option( self::SYNC_TASK_PROGRESS, $progress );

	return $products->products;
}