Automattic\WooCommerce\Blocks\BlockTypes

ClassicTemplate::render_single_product()protectedWC 1.0

Render method for the single product template and parts.

Method of the class: ClassicTemplate{}

Return

String. Rendered block type output.

Usage

// protected - for code of main (parent) or child class
$result = $this->render_single_product();

ClassicTemplate::render_single_product() code WC 8.6.1

protected function render_single_product() {
	ob_start();

	/**
	 * Hook: woocommerce_before_main_content
	 *
	 * Called before rendering the main content for a product.
	 *
	 * @see woocommerce_output_content_wrapper() Outputs opening DIV for the content (priority 10)
	 * @see woocommerce_breadcrumb() Outputs breadcrumb trail to the current product (priority 20)
	 * @see WC_Structured_Data::generate_website_data() Outputs schema markup (priority 30)
	 *
	 * @since 6.3.0
	 */
	do_action( 'woocommerce_before_main_content' );

	$product_query = new \WP_Query(
		array(
			'post_type' => 'product',
			'p'         => get_the_ID(),
		)
	);

	while ( $product_query->have_posts() ) :

		$product_query->the_post();
		wc_get_template_part( 'content', 'single-product' );

	endwhile;

	/**
	 * Hook: woocommerce_after_main_content
	 *
	 * Called after rendering the main content for a product.
	 *
	 * @see woocommerce_output_content_wrapper_end() Outputs closing DIV for the content (priority 10)
	 *
	 * @since 6.3.0
	 */
	do_action( 'woocommerce_after_main_content' );

	wp_reset_postdata();

	return ob_get_clean();
}