Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions

GroupedProductItemSelector::renderprotectedWC 1.0

Render the block.

Method of the class: GroupedProductItemSelector{}

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.

GroupedProductItemSelector::render() code WC 10.8.1

protected function render( $attributes, $content, $block ): string {
	global $product;
	$previous_product = $product;

	$product = AddToCartWithOptionsUtils::get_product_from_context( $block, $previous_product );
	$markup  = '';

	if ( $product ) {
		$is_interactive = false;
		if ( ! $product->is_purchasable() || $product->has_options() || ! $product->is_in_stock() ) {
			$markup = $this->get_button_markup( $product );
		} elseif ( $product->is_sold_individually() ) {
			$is_interactive = true;
			$markup         = $this->get_checkbox_markup( $product );
		} else {
			$is_interactive = true;
			$markup         = $this->get_quantity_selector_markup( $product );
		}

		if ( $is_interactive ) {
			wp_enqueue_script_module( 'woocommerce/add-to-cart-with-options-quantity-selector' );
		}

		if ( $markup ) {
			$markup = '<div class="wp-block-add-to-cart-with-options-grouped-product-item-selector wc-block-add-to-cart-with-options-grouped-product-item-selector">' . $markup . '</div>';
		}
	}

	$product = $previous_product;

	return $markup;
}