Automattic\WooCommerce\Internal\Features\ProductBlockEditor\ProductTemplates

SimpleProductTemplate::add_inventory_group_blocksprivateWC 1.0

Adds the inventory group blocks to the template.

Method of the class: SimpleProductTemplate{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->add_inventory_group_blocks();

SimpleProductTemplate::add_inventory_group_blocks() code WC 10.3.6

private function add_inventory_group_blocks() {
	$inventory_group = $this->get_group_by_id( $this::GROUP_IDS['INVENTORY'] );
	$inventory_group->add_block(
		array(
			'id'         => 'product_variation_notice_inventory_tab',
			'blockName'  => 'woocommerce/product-has-variations-notice',
			'order'      => 10,
			'attributes' => array(
				'content'    => __( 'This product has options, such as size or color. You can now manage each variation\'s inventory and other details individually.', 'woocommerce' ),
				'buttonText' => __( 'Go to Variations', 'woocommerce' ),
				'type'       => 'info',
			),
		)
	);
	// Product Inventory Section.
	$product_inventory_section       = $inventory_group->add_section(
		array(
			'id'         => 'product-inventory-section',
			'order'      => 20,
			'attributes' => array(
				'title'       => __( 'Inventory', 'woocommerce' ),
				'description' => sprintf(
				/* translators: %1$s: Inventory settings link opening tag. %2$s: Inventory settings link closing tag.*/
					__( 'Set up and manage inventory for this product, including status and available quantity. %1$sManage store inventory settings%2$s', 'woocommerce' ),
					'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products&section=inventory' ) . '" target="_blank" rel="noreferrer">',
					'</a>'
				),
				'blockGap'    => 'unit-40',
			),
		)
	);
	$product_inventory_inner_section = $product_inventory_section->add_subsection(
		array(
			'id'    => 'product-inventory-inner-section',
			'order' => 10,
		)
	);
	$inventory_columns               = $product_inventory_inner_section->add_block(
		array(
			'id'        => 'product-inventory-inner-columns',
			'blockName' => 'core/columns',
		)
	);
	$inventory_columns->add_block(
		array(
			'id'        => 'product-inventory-inner-column1',
			'blockName' => 'core/column',
		)
	)->add_block(
		array(
			'id'                => 'product-sku-field',
			'blockName'         => 'woocommerce/product-sku-field',
			'order'             => 10,
			'disableConditions' => array(
				array(
					'expression' => 'editedProduct.type === "variable"',
				),
			),
		)
	);
	$inventory_columns->add_block(
		array(
			'id'        => 'product-inventory-inner-column2',
			'blockName' => 'core/column',
		)
	)->add_block(
		array(
			'id'                => 'product-unique-id-field',
			'blockName'         => 'woocommerce/product-text-field',
			'order'             => 20,
			'attributes'        => array(
				'property' => 'global_unique_id',
				// translators: %1$s GTIN %2$s UPC %3$s EAN %4$s ISBN.
				'label'    => sprintf( __( '%1$s, %2$s, %3$s, or %4$s', 'woocommerce' ), '<abbr title="' . esc_attr__( 'Global Trade Item Number', 'woocommerce' ) . '">' . esc_html__( 'GTIN', 'woocommerce' ) . '</abbr>', '<abbr title="' . esc_attr__( 'Universal Product Code', 'woocommerce' ) . '">' . esc_html__( 'UPC', 'woocommerce' ) . '</abbr>', '<abbr title="' . esc_attr__( 'European Article Number', 'woocommerce' ) . '">' . esc_html__( 'EAN', 'woocommerce' ) . '</abbr>', '<abbr title="' . esc_attr__( 'International Standard Book Number', 'woocommerce' ) . '">' . esc_html__( 'ISBN', 'woocommerce' ) . '</abbr>' ),
				'tooltip'  => __( 'Enter a barcode or any other identifier unique to this product. It can help you list this product on other channels or marketplaces.', 'woocommerce' ),
				'pattern'  => array(
					'value'   => '[0-9\-]*',
					'message' => __( 'Please enter only numbers and hyphens (-).', 'woocommerce' ),
				),
			),
			'disableConditions' => array(
				array(
					'expression' => 'editedProduct.type === "variable"',
				),
			),
		)
	);

	$manage_stock = 'yes' === get_option( 'woocommerce_manage_stock' );
	$product_inventory_inner_section->add_block(
		array(
			'id'                => 'product-track-stock',
			'blockName'         => 'woocommerce/product-toggle-field',
			'order'             => 20,
			'attributes'        => array(
				'label'        => __( 'Track inventory', 'woocommerce' ),
				'property'     => 'manage_stock',
				'disabled'     => ! $manage_stock,
				'disabledCopy' => ! $manage_stock ? sprintf(
					/* translators: %1$s: Learn more link opening tag. %2$s: Learn more link closing tag.*/
					__( 'Per your %1$sstore settings%2$s, inventory management is <strong>disabled</strong>.', 'woocommerce' ),
					'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products&section=inventory' ) . '" target="_blank" rel="noreferrer">',
					'</a>'
				) : null,
			),
			'hideConditions'    => array(
				array(
					'expression' => 'editedProduct.type === "external" || editedProduct.type === "grouped"',
				),
			),
			'disableConditions' => array(
				array(
					'expression' => 'editedProduct.type === "variable"',
				),
			),
		)
	);
	$product_inventory_quantity_hide_conditions   = array(
		array(
			'expression' => 'editedProduct.manage_stock === false',
		),
	);
	$product_inventory_quantity_hide_conditions[] = array(
		'expression' => 'editedProduct.type === "grouped"',
	);
	$product_inventory_inner_section->add_block(
		array(
			'id'             => 'product-inventory-quantity',
			'blockName'      => 'woocommerce/product-inventory-quantity-field',
			'order'          => 30,
			'hideConditions' => $product_inventory_quantity_hide_conditions,
		)
	);
	$product_stock_status_hide_conditions   = array(
		array(
			'expression' => 'editedProduct.manage_stock === true',
		),
	);
	$product_stock_status_hide_conditions[] = array(
		'expression' => 'editedProduct.type === "grouped"',
	);
	$product_inventory_section->add_block(
		array(
			'id'                => 'product-stock-status',
			'blockName'         => 'woocommerce/product-radio-field',
			'order'             => 10,
			'attributes'        => array(
				'title'    => __( 'Stock status', 'woocommerce' ),
				'property' => 'stock_status',
				'options'  => array(
					array(
						'label' => __( 'In stock', 'woocommerce' ),
						'value' => ProductStockStatus::IN_STOCK,
					),
					array(
						'label' => __( 'Out of stock', 'woocommerce' ),
						'value' => ProductStockStatus::OUT_OF_STOCK,
					),
					array(
						'label' => __( 'On backorder', 'woocommerce' ),
						'value' => ProductStockStatus::ON_BACKORDER,
					),
				),
			),
			'hideConditions'    => $product_stock_status_hide_conditions,
			'disableConditions' => array(
				array(
					'expression' => 'editedProduct.type === "variable"',
				),
			),
		)
	);

	$product_inventory_section->add_block(
		array(
			'id'         => 'product-purchase-note',
			'blockName'  => 'woocommerce/product-text-area-field',
			'order'      => 20,
			'attributes' => array(
				'property'    => 'purchase_note',
				'label'       => __( 'Post-purchase note', 'woocommerce' ),
				'placeholder' => __( 'Enter an optional note attached to the order confirmation message sent to the shopper.', 'woocommerce' ),
				'lock'        => array(
					'move' => true,
				),
			),
		)
	);

	$product_inventory_advanced         = $product_inventory_section->add_block(
		array(
			'id'             => 'product-inventory-advanced',
			'blockName'      => 'woocommerce/product-collapsible',
			'order'          => 30,
			'attributes'     => array(
				'toggleText'       => __( 'Advanced', 'woocommerce' ),
				'initialCollapsed' => true,
				'persistRender'    => true,
			),
			'hideConditions' => array(
				array(
					'expression' => 'editedProduct.type === "grouped"',
				),
			),
		)
	);
	$product_inventory_advanced_wrapper = $product_inventory_advanced->add_block(
		array(
			'blockName'  => 'woocommerce/product-section',
			'order'      => 10,
			'attributes' => array(
				'blockGap' => 'unit-40',
			),
		)
	);
	$product_inventory_advanced_wrapper->add_block(
		array(
			'id'             => 'product-out-of-stock',
			'blockName'      => 'woocommerce/product-radio-field',
			'order'          => 10,
			'attributes'     => array(
				'title'    => __( 'When out of stock', 'woocommerce' ),
				'property' => 'backorders',
				'options'  => array(
					array(
						'label' => __( 'Allow purchases', 'woocommerce' ),
						'value' => 'yes',
					),
					array(
						'label' => __(
							'Allow purchases, but notify customers',
							'woocommerce'
						),
						'value' => 'notify',
					),
					array(
						'label' => __( "Don't allow purchases", 'woocommerce' ),
						'value' => 'no',
					),
				),
			),
			'hideConditions' => array(
				array(
					'expression' => 'editedProduct.manage_stock === false',
				),
			),
		)
	);
	$product_inventory_advanced_wrapper->add_block(
		array(
			'id'             => 'product-inventory-email',
			'blockName'      => 'woocommerce/product-inventory-email-field',
			'order'          => 20,
			'hideConditions' => array(
				array(
					'expression' => 'editedProduct.manage_stock === false',
				),
			),
		)
	);

	$product_inventory_advanced_wrapper->add_block(
		array(
			'id'         => 'product-limit-purchase',
			'blockName'  => 'woocommerce/product-checkbox-field',
			'order'      => 20,
			'attributes' => array(
				'title'    => __(
					'Restrictions',
					'woocommerce'
				),
				'label'    => __(
					'Limit purchases to 1 item per order',
					'woocommerce'
				),
				'property' => 'sold_individually',
				'tooltip'  => __(
					'When checked, customers will be able to purchase only 1 item in a single order. This is particularly useful for items that have limited quantity, like art or handmade goods.',
					'woocommerce'
				),
			),
		)
	);
}