Automattic\WooCommerce\Blocks\BlockTypes
AddToCartWithOptionsGroupedProductSelectorItemTemplate::get_product_row()
Get product row HTML.
Метод класса: AddToCartWithOptionsGroupedProductSelectorItemTemplate{}
Хуков нет.
Возвращает
Строку
. Row HTML
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_product_row( $product_id, $attributes, $block ): string;
- $product_id(строка) (обязательный)
- Product ID.
- $attributes(массив) (обязательный)
- Block attributes.
- $block(WP_Block) (обязательный)
- The Block.
Код AddToCartWithOptionsGroupedProductSelectorItemTemplate::get_product_row() AddToCartWithOptionsGroupedProductSelectorItemTemplate::get product row WC 9.8.5
private function get_product_row( $product_id, $attributes, $block ): string { global $post; $previous_post = $post; // Since this template uses the core/post-title block to show the product name // a temporally replacement of the global post is needed. This is reverted back // to its initial post value that is stored in the $previous_post variable. $post = get_post( $product_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited // Get an instance of the current Post Template block. $block_instance = $block->parsed_block; $new_block = new WP_Block( $block_instance, array( 'postType' => 'product', 'postId' => $post->ID, ), ); // Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling // `render_callback` and ensure that no wrapper markup is included. $block_content = $new_block->render( array( 'dynamic' => false ) ); $post = $previous_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited return $block_content; }