Automattic\WooCommerce\Blocks\BlockTypes
AddToCartWithOptions::render()
Render the block.
Метод класса: AddToCartWithOptions{}
Хуки из метода
Возвращает
Строку
. | void Rendered block output.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
- $content(строка) (обязательный)
- Block content.
- $block(WP_Block) (обязательный)
- Block instance.
Код AddToCartWithOptions::render() AddToCartWithOptions::render WC 9.7.1
protected function render( $attributes, $content, $block ) { global $product; $post_id = $block->context['postId']; if ( ! isset( $post_id ) ) { return ''; } $previous_product = $product; $product = wc_get_product( $post_id ); if ( ! $product instanceof \WC_Product ) { $product = $previous_product; return ''; } $is_external_product_with_url = $product instanceof \WC_Product_External && $product->get_product_url(); /** * Filter to modify the add to cart with options HTML output. * * @since 9.6.0 * * @param string $content The HTML content for the add to cart with options block. */ $product_html = apply_filters( 'woocommerce_add_to_cart_with_options_html', $content ); if ( ! $product_html ) { $product = $previous_product; return ''; } $product_name = $product->get_name(); $parsed_attributes = $this->parse_attributes( $attributes ); $is_descendent_of_single_product_block = $parsed_attributes['isDescendentOfSingleProductBlock']; if ( ! $is_external_product_with_url ) { $product_html = $this->add_is_descendent_of_single_product_block_hidden_input_to_product_form( $product_html, $is_descendent_of_single_product_block ); } $classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array(), array( 'extra_classes' ) ); $product_classname = $is_descendent_of_single_product_block ? 'product' : ''; $classes = implode( ' ', array_filter( array( 'wp-block-add-to-cart-with-options wc-block-add-to-cart-with-options', esc_attr( $classes_and_styles['classes'] ), esc_attr( $product_classname ), 'wc-block-add-to-cart-with-options--input', ) ) ); $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes, 'style' => esc_attr( $classes_and_styles['styles'] ), ) ); $form = sprintf( '<div %1$s %2$s>%3$s</div>', $wrapper_attributes, '', $product_html ); $product = $previous_product; return $form; }