Automattic\WooCommerce\Blocks\BlockTypes

AddToCartWithOptionsVariationSelector::render_variation_selector()protectedWC 1.0

Render variation selector dropdown.

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

Хуков нет.

Возвращает

Строку. Rendered dropdown HTML.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->render_variation_selector( $product, $attribute_name, $options ): string;
$product(WC_Product) (обязательный)
The product object.
$attribute_name(строка) (обязательный)
Name of the attribute.
$options(массив) (обязательный)
Available options for this attribute.

Код AddToCartWithOptionsVariationSelector::render_variation_selector() WC 9.8.5

protected function render_variation_selector( $product, $attribute_name, $options ): string {
	$selected  = $this->get_selected_attribute_value( $product, $attribute_name );
	$select_id = esc_attr( 'attribute_' . sanitize_title( $attribute_name ) );

	$html = sprintf(
		'<select id="%1$s"
			class="wc-block-product-add-to-cart-attribute-select"
			name="%1$s"
			data-attribute_name="attribute_%2$s">',
		$select_id,
		esc_attr( sanitize_title( $attribute_name ) )
	);

	$html .= '<option value="">' . esc_html__( 'Choose an option', 'woocommerce' ) . '</option>';
	$html .= $this->get_variation_options_html( $product, $attribute_name, $options, $selected, taxonomy_exists( $attribute_name ) );
	$html .= '</select>';

	return $html;
}