Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions
GroupedProductItemLabel::render
Render the block.
Метод класса: GroupedProductItemLabel{}
Хуков нет.
Возвращает
string. Rendered block output.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render( $attributes, $content, $block ): string;
- $attributes(массив) (обязательный)
- Block attributes.
- $content(строка) (обязательный)
- Block content.
- $block(WP_Block) (обязательный)
- Block instance.
Код GroupedProductItemLabel::render() GroupedProductItemLabel::render WC 11.3.0
protected function render( $attributes, $content, $block ): string {
$product = AddToCartWithOptionsUtils::get_product_from_context( $block, $GLOBALS['product'] );
$markup = '';
if ( $product ) {
$wrapper_attributes = get_block_wrapper_attributes();
$title = $product->get_name();
if ( ! $product->is_purchasable() || $product->has_options() || ! $product->is_in_stock() ) {
$markup = sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
esc_html( $title )
);
} else {
// Checkbox.
$markup = sprintf(
'<label %1$s for="%2$s">%3$s</label>',
$wrapper_attributes,
esc_attr( 'quantity_' . $product->get_id() ),
esc_html( $title )
);
}
}
return $markup;
}