WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
класс не описан

SingleProduct() WC 1.0

SingleProduct class.

Хуков нет.

Возвращает

Null. Ничего.

Использование

$SingleProduct = new SingleProduct();
// use class methods

Методы

  1. enqueue_scripts( array $attributes = [] )
  2. register_block_type()
  3. render( $attributes = array(), $content = '' )

Код SingleProduct: woocommerce/packages/woocommerce-blocks/src/BlockTypes/SingleProduct.php WC 4.3.1

<?php
class SingleProduct extends AbstractBlock {
	/**
	 * Block name.
	 *
	 * @var string
	 */
	protected $block_name = 'single-product';

	/**
	 * Registers the block type with WordPress.
	 */
	public function register_block_type() {
		register_block_type(
			$this->namespace . '/' . $this->block_name,
			array(
				'render_callback' => array( $this, 'render' ),
				'editor_script'   => 'wc-' . $this->block_name . '-block',
				'editor_style'    => 'wc-block-editor',
				'style'           => [ 'wc-block-style', 'wc-block-vendors-style' ],
				'script'          => 'wc-' . $this->block_name . '-frontend',
			)
		);
	}

	/**
	 * Register/enqueue scripts used for this block.
	 *
	 * @param array $attributes  Any attributes that currently are available from the block.
	 *                           Note, this will be empty in the editor context when the block is
	 *                           not in the post content on editor load.
	 */
	protected function enqueue_scripts( array $attributes = [] ) {
		Assets::register_block_script( $this->block_name . '-frontend', $this->block_name . '-frontend' );
	}

	/**
	 * Render the block on the frontend.
	 *
	 * @param array  $attributes Block attributes. Default empty array.
	 * @param string $content    Block content. Default empty string.
	 * @return string Rendered block type output.
	 */
	public function render( $attributes = array(), $content = '' ) {
		$block_attributes = is_a( $attributes, '\WP_Block' ) ? $attributes->attributes : $attributes;

		$this->enqueue_assets( $block_attributes );

		return $this->inject_html_data_attributes( $content, $block_attributes );
	}
}