Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions

GroupedProductItemLabel::renderprotectedWC 1.0

Render the block.

Method of the class: GroupedProductItemLabel{}

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.

GroupedProductItemLabel::render() code WC 10.8.1

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;
}