Automattic\WooCommerce\Admin\Features\ProductBlockEditor

ProductTemplate{}WC 1.0

Deprecated since 10.9.0 Product editor extension APIs will be removed in WooCommerce 11.0.. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

The Product Template that represents the relation between the Product and the LayoutTemplate (ProductFormTemplateInterface)

No Hooks.

Usage

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

Methods

  1. public __construct( array $data )
  2. public get_description()
  3. public get_icon()
  4. public get_id()
  5. public get_is_selectable_by_user()
  6. public get_layout_template_id()
  7. public get_order()
  8. public get_product_data()
  9. public get_title()
  10. public set_description( string $description )
  11. public set_icon( string $icon )
  12. public set_layout_template_id( string $layout_template_id )
  13. public set_order( int $order )
  14. public to_json()
  15. ERROR: no method name found on line `}`
  16. ERROR: no method name found on line `/**`
  17. ERROR: no method name found on line `* The template order.`
  18. ERROR: no method name found on line `private $title;`
  19. ERROR: no method name found on line `/**`

Notes

Changelog

Deprecated since 10.9.0 Product editor extension APIs will be removed in WooCommerce 11.0.

ProductTemplate{} code WC 10.9.1

class ProductTemplate {
	/**
	 * The template id.
	 *
	 * @var string
	 */
	private $id;

	/**
	 * The template title.
	 *
	 * @var string
	 */
	private $title;

	/**
	 * The product data.
	 *
	 * @var array
	 */
	private $product_data;

	/**
	 * The template order.
	 *
	 * @var Integer
	 */
	private $order = 999;

	/**
	 * The layout template id.
	 *
	 * @var string
	 */
	private $layout_template_id = null;

	/**
	 * The template description.
	 *
	 * @var string
	 */
	private $description = null;

	/**
	 * The template icon.
	 *
	 * @var string
	 */
	private $icon = null;

	/**
	 * If the template is directly selectable through the UI.
	 *
	 * @var boolean
	 */
	private $is_selectable_by_user = true;

	/**
	 * ProductTemplate constructor
	 *
	 * @param array $data The data.
	 */
	public function __construct( array $data ) {
		$this->id           = $data['id'];
		$this->title        = $data['title'];
		$this->product_data = $data['product_data'];

		if ( isset( $data['order'] ) ) {
			$this->order = $data['order'];
		}

		if ( isset( $data['layout_template_id'] ) ) {
			$this->layout_template_id = $data['layout_template_id'];
		}

		if ( isset( $data['description'] ) ) {
			$this->description = $data['description'];
		}

		if ( isset( $data['icon'] ) ) {
			$this->icon = $data['icon'];
		}

		if ( isset( $data['is_selectable_by_user'] ) ) {
			$this->is_selectable_by_user = $data['is_selectable_by_user'];
		}
	}

	/**
	 * Get the template ID.
	 *
	 * @return string The ID.
	 */
	public function get_id() {
		return $this->id;
	}

	/**
	 * Get the template title.
	 *
	 * @return string The title.
	 */
	public function get_title() {
		return $this->title;
	}

	/**
	 * Get the layout template ID.
	 *
	 * @return string The layout template ID.
	 */
	public function get_layout_template_id() {
		return $this->layout_template_id;
	}

	/**
	 * Set the layout template ID.
	 *
	 * @param string $layout_template_id The layout template ID.
	 */
	public function set_layout_template_id( string $layout_template_id ) {
		$this->layout_template_id = $layout_template_id;
	}

	/**
	 * Get the product data.
	 *
	 * @return array The product data.
	 */
	public function get_product_data() {
		return $this->product_data;
	}

	/**
	 * Get the template description.
	 *
	 * @return string The description.
	 */
	public function get_description() {
		return $this->description;
	}

	/**
	 * Set the template description.
	 *
	 * @param string $description The template description.
	 */
	public function set_description( string $description ) {
		$this->description = $description;
	}

	/**
	 * Get the template icon.
	 *
	 * @return string The icon.
	 */
	public function get_icon() {
		return $this->icon;
	}

	/**
	 * Set the template icon.
	 *
	 * @see https://github.com/WordPress/gutenberg/tree/trunk/packages/icons.
	 *
	 * @param string $icon The icon name from the @wordpress/components or a url for an external image resource.
	 */
	public function set_icon( string $icon ) {
		$this->icon = $icon;
	}

	/**
	 * Get the template order.
	 *
	 * @return int The order.
	 */
	public function get_order() {
		return $this->order;
	}

	/**
	 * Get the selectable attribute.
	 *
	 * @return boolean Selectable.
	 */
	public function get_is_selectable_by_user() {
		return $this->is_selectable_by_user;
	}

	/**
	 * Set the template order.
	 *
	 * @param int $order The template order.
	 */
	public function set_order( int $order ) {
		$this->order = $order;
	}

	/**
	 * Get the product template as JSON like.
	 *
	 * @return array The JSON.
	 */
	public function to_json() {
		return array(
			'id'                 => $this->get_id(),
			'title'              => $this->get_title(),
			'description'        => $this->get_description(),
			'icon'               => $this->get_icon(),
			'order'              => $this->get_order(),
			'layoutTemplateId'   => $this->get_layout_template_id(),
			'productData'        => $this->get_product_data(),
			'isSelectableByUser' => $this->get_is_selectable_by_user(),
		);
	}
}