Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions

GroupedProductItemSelector::get_checkbox_markupprivateWC 1.0

Gets the checkbox markup for a product.

Method of the class: GroupedProductItemSelector{}

No Hooks.

Returns

String. The HTML markup for the checkbox input and label.

Usage

// private - for code of main (parent) class only
$result = $this->get_checkbox_markup( $product );
$product(WC_Product) (required)
The product object.

GroupedProductItemSelector::get_checkbox_markup() code WC 10.6.2

private function get_checkbox_markup( $product ) {
	if ( $product->is_on_sale() ) {
		$label = sprintf(
			/* translators: %1$s: Product name. %2$s: Sale price. %3$s: Regular price */
			esc_html__( 'Buy one of %1$s on sale for %2$s, original price was %3$s', 'woocommerce' ),
			esc_html( $product->get_name() ),
			esc_html( wp_strip_all_tags( wc_price( $product->get_price() ) ) ),
			esc_html( wp_strip_all_tags( wc_price( $product->get_regular_price() ) ) )
		);
	} else {
		$label = sprintf(
			/* translators: %1$s: Product name. %2$s: Product price */
			esc_html__( 'Buy one of %1$s for %2$s', 'woocommerce' ),
			esc_html( $product->get_name() ),
			esc_html( wp_strip_all_tags( wc_price( $product->get_price() ) ) )
		);
	}

	$context_attribute = wp_interactivity_data_wp_context( array( 'productId' => $product->get_id() ) );
	return '<input type="checkbox" name="' . esc_attr( 'quantity[' . $product->get_id() . ']' ) . '" value="1" class="wc-grouped-product-add-to-cart-checkbox" id="' . esc_attr( 'quantity_' . $product->get_id() ) . '" data-wp-interactive="woocommerce/add-to-cart-with-options-quantity-selector" data-wp-on--change="actions.handleQuantityCheckboxChange" ' . $context_attribute . ' aria-label="' . esc_attr( $label ) . '"/>';
}