Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions
VariationSelectorAttributeOptions::render
Render the block.
Method of the class: VariationSelectorAttributeOptions{}
No Hooks.
Returns
String. Rendered block output.
Usage
// protected - for code of main (parent) or child class $result = $this->render( $attributes, $content, $block ): string;
- $attributes(array) (required)
- Block attributes.
- $content(string) (required)
- Block content.
- $block(WP_Block) (required)
- Block instance.
VariationSelectorAttributeOptions::render() VariationSelectorAttributeOptions::render code WC 10.8.1
protected function render( $attributes, $content, $block ): string {
if (
! isset(
$block->context['woocommerce/attributeName'],
$block->context['woocommerce/attributeId'],
$block->context['woocommerce/attributeTerms']
)
) {
return '';
}
$attribute_slug = wc_variation_attribute_name( $block->context['woocommerce/attributeName'] );
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array(), array( 'extra_classes' ) );
$option_style = array_key_exists( 'optionStyle', $attributes ) ? $attributes['optionStyle'] : null;
// During the beta period, `optionStyle` was called `style`, so we check
// `style` for backwards compatibility.
if ( ! $option_style && array_key_exists( 'style', $attributes ) && 'dropdown' === $attributes['style'] ) {
$option_style = 'dropdown';
}
$wrapper_attributes = get_block_wrapper_attributes(
array(
'class' => $classes_and_styles['classes'],
'style' => $classes_and_styles['styles'],
)
);
if ( 'dropdown' === $option_style ) {
$content = $this->render_dropdown( $attributes, $content, $block );
} else {
$content = $this->render_pills( $attributes, $content, $block );
}
return sprintf(
'<div %s>%s</div>',
$wrapper_attributes,
$content
);
}