Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions

VariationSelectorAttribute::get_product_rowprivateWC 1.0

Get product row HTML.

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

Хуков нет.

Возвращает

Строку. Row HTML

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

// private - только в коде основоного (родительского) класса
$result = $this->get_product_row( $attribute_name, $product_attribute_terms, $block ): string;
$attribute_name(строка) (обязательный)
Product Attribute Name.
$product_attribute_terms(массив) (обязательный)
Product Attribute Terms.
$block(WP_Block) (обязательный)
The Block.

Код VariationSelectorAttribute::get_product_row() WC 10.3.6

private function get_product_row( $attribute_name, $product_attribute_terms, $block ): string {
	global $product;

	$attribute_terms    = $this->get_terms( $attribute_name, $product_attribute_terms );
	$product_variations = $product->get_available_variations();

	// Filter out terms which are not available in any product variation.
	$attribute_terms = array_filter(
		$attribute_terms,
		function ( $term ) use ( $product_variations, $attribute_name, $attribute_terms ) {
			foreach ( $product_variations as $product_variation ) {
				if (
					$term['value'] === $product_variation['attributes'][ wc_variation_attribute_name( $attribute_name ) ] ||
					'' === $product_variation['attributes'][ wc_variation_attribute_name( $attribute_name ) ]
				) {
					return true;
				}
			}
		}
	);

	if ( empty( $attribute_terms ) ) {
		return '';
	}

	$block_content = AddToCartWithOptionsUtils::render_block_with_context(
		$block,
		array(
			'woocommerce/attributeId'    => 'wc_product_attribute_' . uniqid(),
			'woocommerce/attributeName'  => $attribute_name,
			'woocommerce/attributeTerms' => $attribute_terms,
		),
	);

	// Render the inner blocks of the Variation Selector Item Template block with `dynamic` set to `false`
	// to prevent calling `render_callback` and ensure that no wrapper markup is included.
	return $block_content;
}