Automattic\WooCommerce\Internal\ProductAttributesLookup

DataRegenerator::do_regeneration_step()privateWC 1.0

Perform one regeneration step: grabs a chunk of products and creates the appropriate entries for them in the lookup table.

Method of the class: DataRegenerator{}

Return

true|false. True if more steps need to be run, false otherwise.

Usage

// private - for code of main (parent) class only
$result = $this->do_regeneration_step();

DataRegenerator::do_regeneration_step() code WC 8.7.0

private function do_regeneration_step() {
	/**
	 * Filter to alter the count of products that will be processed in each step of the product attributes lookup table regeneration process.
	 *
	 * @since 6.3
	 * @param int $count Default processing step size.
	 */
	$products_per_generation_step = apply_filters( 'woocommerce_attribute_lookup_regeneration_step_size', self::PRODUCTS_PER_GENERATION_STEP );

	$products_already_processed = get_option( 'woocommerce_attribute_lookup_processed_count', 0 );

	$product_ids = WC()->call_function(
		'wc_get_products',
		array(
			'limit'   => $products_per_generation_step,
			'offset'  => $products_already_processed,
			'orderby' => array(
				'ID' => 'ASC',
			),
			'return'  => 'ids',
		)
	);

	if ( ! is_array( $product_ids ) || empty( $product_ids ) ) {
		return false;
	}

	foreach ( $product_ids as $id ) {
		$this->data_store->create_data_for_product( $id );
	}

	$products_already_processed += count( $product_ids );
	update_option( 'woocommerce_attribute_lookup_processed_count', $products_already_processed );

	$last_product_id_to_process = get_option( 'woocommerce_attribute_lookup_last_product_id_to_process', PHP_INT_MAX );
	return end( $product_ids ) < $last_product_id_to_process;
}