WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Internal\ProductAttributesLookup

LookupDataStore::create_data_for_variable_product() private WC 1.0

Create lookup table entries for a variable product. Assumes that no entries exist yet.

{} It's a method of the class: LookupDataStore{}

No Hooks.

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->create_data_for_variable_product( $product );
$product(WC_Product_Variable) (required)
The product to create the entries for.

Code of LookupDataStore::create_data_for_variable_product() WC 5.9.0

private function create_data_for_variable_product( \WC_Product_Variable $product ) {
	$product_attributes_data       = $this->get_attribute_taxonomies( $product );
	$variation_attributes_data     = array_filter(
		$product_attributes_data,
		function( $item ) {
			return $item['used_for_variations'];
		}
	);
	$non_variation_attributes_data = array_filter(
		$product_attributes_data,
		function( $item ) {
			return ! $item['used_for_variations'];
		}
	);

	$main_product_has_stock = $product->is_in_stock();
	$main_product_id        = $product->get_id();

	foreach ( $non_variation_attributes_data as $taxonomy => $data ) {
		$term_ids = $data['term_ids'];
		foreach ( $term_ids as $term_id ) {
			$this->insert_lookup_table_data( $main_product_id, $main_product_id, $taxonomy, $term_id, false, $main_product_has_stock );
		}
	}

	$term_ids_by_slug_cache = $this->get_term_ids_by_slug_cache( array_keys( $variation_attributes_data ) );
	$variations             = $this->get_variations_of( $product );

	foreach ( $variation_attributes_data as $taxonomy => $data ) {
		foreach ( $variations as $variation ) {
			$this->insert_lookup_table_data_for_variation( $variation, $taxonomy, $main_product_id, $data['term_ids'], $term_ids_by_slug_cache );
		}
	}
}