Automattic\WooCommerce\Blocks\BlockTypes

ClassicShortcode::render()protectedWC 1.0

Render method for the Classic Template block. This method will determine which template to render.

Method of the class: ClassicShortcode{}

No Hooks.

Return

String. | void Rendered block type output.

Usage

// protected - for code of main (parent) or child class
$result = $this->render( $attributes, $content, $block );
$attributes(array) (required)
Block attributes.
$content(string) (required)
Block content.
$block(WP_Block) (required)
Block instance.

ClassicShortcode::render() code WC 9.0.1

protected function render( $attributes, $content, $block ) {
	if ( ! isset( $attributes['shortcode'] ) ) {
		return;
	}

	/**
	 * We need to load the scripts here because when using block templates wp_head() gets run after the block
	 * template. As a result we are trying to enqueue required scripts before we have even registered them.
	 *
	 * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5328#issuecomment-989013447
	 */
	if ( class_exists( 'WC_Frontend_Scripts' ) ) {
		$frontend_scripts = new WC_Frontend_Scripts();
		$frontend_scripts::load_scripts();
	}

	if ( 'cart' === $attributes['shortcode'] ) {
		return $this->render_cart( $attributes );
	}

	if ( 'checkout' === $attributes['shortcode'] ) {
		return $this->render_checkout( $attributes );
	}

	return "You're using the ClassicShortcode block";
}