Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions
VariationSelectorAttributeName::render
Render the block.
Method of the class: VariationSelectorAttributeName{}
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.
VariationSelectorAttributeName::render() VariationSelectorAttributeName::render code WC 10.8.1
protected function render( $attributes, $content, $block ): string {
if (
! isset(
$block->context['woocommerce/attributeId'],
$block->context['woocommerce/attributeName']
)
) {
return '';
}
$attribute_id = $block->context['woocommerce/attributeId'];
$attribute_name = $block->context['woocommerce/attributeName'];
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array(), array( 'extra_classes' ) );
$wrapper_attributes = get_block_wrapper_attributes(
array(
'class' => esc_attr( $classes_and_styles['classes'] ),
'for' => esc_attr( $attribute_id ),
'id' => esc_attr( $attribute_id . '_label' ),
'style' => esc_attr( $classes_and_styles['styles'] ),
)
);
$label_text = esc_html( wc_attribute_label( $attribute_name ) );
return sprintf(
'<label %s>%s</label>',
$wrapper_attributes,
$label_text
);
}