Automattic\WooCommerce\Internal\Features\ProductBlockEditor\ProductTemplates
SimpleProductTemplate::add_general_group_blocks │ private │ WC 1.0
Adds the general group blocks to the template.
Метод класса: SimpleProductTemplate{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->add_general_group_blocks();
Код SimpleProductTemplate::add_general_group_blocks() SimpleProductTemplate::add general group blocks WC 10.4.2
private function add_general_group_blocks() {
$is_calc_taxes_enabled = wc_tax_enabled();
$general_group = $this->get_group_by_id( $this::GROUP_IDS['GENERAL'] );
$general_group->add_block(
array(
'id' => 'product_variation_notice_general_tab',
'blockName' => 'woocommerce/product-has-variations-notice',
'order' => 10,
'attributes' => array(
'content' => __( 'This product has options, such as size or color. You can manage each variation\'s images, downloads, and other details individually.', 'woocommerce' ),
'buttonText' => __( 'Go to Variations', 'woocommerce' ),
'type' => 'info',
),
)
);
// Basic Details Section.
$basic_details = $general_group->add_section(
array(
'id' => 'basic-details',
'order' => 10,
'attributes' => array(
'title' => __( 'Basic details', 'woocommerce' ),
'description' => __( 'This info will be displayed on the product page, category pages, social media, and search results.', 'woocommerce' ),
),
)
);
$basic_details->add_block(
array(
'id' => 'product-details-section-description',
'blockName' => 'woocommerce/product-details-section-description',
'order' => 10,
)
);
$basic_details->add_block(
array(
'id' => 'product-name',
'blockName' => 'woocommerce/product-name-field',
'order' => 10,
'attributes' => array(
'name' => 'Product name',
'autoFocus' => true,
'metadata' => array(
'bindings' => array(
'value' => array(
'source' => 'woocommerce/entity-product',
'args' => array(
'prop' => 'name',
),
),
),
),
),
)
);
// Product Pricing columns.
$pricing_columns = $basic_details->add_block(
array(
'id' => 'product-pricing-group-pricing-columns',
'blockName' => 'core/columns',
'order' => 10,
)
);
$pricing_column_1 = $pricing_columns->add_block(
array(
'id' => 'product-pricing-group-pricing-column-1',
'blockName' => 'core/column',
'order' => 10,
'attributes' => array(
'templateLock' => 'all',
),
)
);
$pricing_column_1->add_block(
array(
'id' => 'product-pricing-regular-price',
'blockName' => 'woocommerce/product-regular-price-field',
'order' => 10,
'attributes' => array(
'name' => 'regular_price',
'label' => __( 'Regular price', 'woocommerce' ),
'help' => $is_calc_taxes_enabled ? null : sprintf(
/* translators: %1$s: store settings link opening tag. %2$s: store settings link closing tag.*/
__( 'Per your %1$sstore settings%2$s, taxes are not enabled.', 'woocommerce' ),
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=general' ) . '" target="_blank" rel="noreferrer">',
'</a>'
),
),
'disableConditions' => array(
array(
'expression' => 'editedProduct.type === "variable"',
),
array(
'expression' => 'editedProduct.type === "grouped"',
),
),
)
);
$pricing_column_2 = $pricing_columns->add_block(
array(
'id' => 'product-pricing-group-pricing-column-2',
'blockName' => 'core/column',
'order' => 20,
'attributes' => array(
'templateLock' => 'all',
),
)
);
$pricing_column_2->add_block(
array(
'id' => 'product-pricing-sale-price',
'blockName' => 'woocommerce/product-sale-price-field',
'order' => 10,
'attributes' => array(
'label' => __( 'Sale price', 'woocommerce' ),
),
'disableConditions' => array(
array(
'expression' => 'editedProduct.type === "variable"',
),
array(
'expression' => 'editedProduct.type === "grouped"',
),
),
)
);
$basic_details->add_block(
array(
'id' => 'product-pricing-schedule-sale-fields',
'blockName' => 'woocommerce/product-schedule-sale-fields',
'order' => 20,
)
);
if ( $is_calc_taxes_enabled ) {
$basic_details->add_block(
array(
'id' => 'product-sale-tax',
'blockName' => 'woocommerce/product-radio-field',
'order' => 30,
'attributes' => array(
'title' => __( 'Charge sales tax on', 'woocommerce' ),
'property' => 'tax_status',
'options' => array(
array(
'label' => __( 'Product and shipping', 'woocommerce' ),
'value' => ProductTaxStatus::TAXABLE,
),
array(
'label' => __( 'Only shipping', 'woocommerce' ),
'value' => 'shipping',
),
array(
'label' => __( "Don't charge tax", 'woocommerce' ),
'value' => 'none',
),
),
),
)
);
$pricing_advanced_block = $basic_details->add_block(
array(
'id' => 'product-pricing-advanced',
'blockName' => 'woocommerce/product-collapsible',
'order' => 40,
'attributes' => array(
'toggleText' => __( 'Advanced', 'woocommerce' ),
'initialCollapsed' => true,
'persistRender' => true,
),
)
);
$pricing_advanced_block->add_block(
array(
'id' => 'product-tax-class',
'blockName' => 'woocommerce/product-select-field',
'order' => 10,
'attributes' => array(
'label' => __( 'Tax class', 'woocommerce' ),
'help' => sprintf(
/* translators: %1$s: Learn more link opening tag. %2$s: Learn more link closing tag.*/
__( 'Apply a tax rate if this product qualifies for tax reduction or exemption. %1$sLearn more%2$s', 'woocommerce' ),
'<a href="https://woocommerce.com/document/setting-up-taxes-in-woocommerce/#shipping-tax-class" target="_blank" rel="noreferrer">',
'</a>'
),
'property' => 'tax_class',
'options' => self::get_tax_classes(),
),
)
);
}
$basic_details->add_block(
array(
'id' => 'product-summary',
'blockName' => 'woocommerce/product-text-area-field',
'order' => 50,
'attributes' => array(
'label' => __( 'Summary', 'woocommerce' ),
'help' => __(
"Summarize this product in 1-2 short sentences. We'll show it at the top of the page.",
'woocommerce'
),
'property' => 'short_description',
'lock' => array(
'move' => true,
),
),
)
);
// Description section.
$description_section = $general_group->add_section(
array(
'id' => 'product-description-section',
'order' => 20,
'attributes' => array(
'title' => __( 'Description', 'woocommerce' ),
'description' => __( 'What makes this product unique? What are its most important features? Enrich the product page by adding rich content using blocks.', 'woocommerce' ),
),
)
);
$description_field_block = $description_section->add_block(
array(
'id' => 'product-description',
'blockName' => 'woocommerce/product-description-field',
'order' => 10,
)
);
$description_field_block->add_block(
array(
'id' => 'product-description__content',
'blockName' => 'woocommerce/product-summary-field',
'order' => 10,
'attributes' => array(
'helpText' => null,
'label' => null,
'property' => 'description',
'lock' => array(
'move' => true,
),
),
)
);
// External/Affiliate section.
$buy_button_section = $general_group->add_section(
array(
'id' => 'product-buy-button-section',
'order' => 30,
'attributes' => array(
'title' => __( 'Buy button', 'woocommerce' ),
'description' => __( 'Add a link and choose a label for the button linked to a product sold elsewhere.', 'woocommerce' ),
),
'hideConditions' => array(
array(
'expression' => 'editedProduct.type !== "external"',
),
),
)
);
$buy_button_section->add_block(
array(
'id' => 'product-external-url',
'blockName' => 'woocommerce/product-text-field',
'order' => 10,
'attributes' => array(
'property' => 'external_url',
'label' => __( 'Link to the external product', 'woocommerce' ),
'placeholder' => __( 'Enter the external URL to the product', 'woocommerce' ),
'suffix' => true,
'type' => array(
'value' => 'url',
'message' => __( 'Link to the external product is an invalid URL.', 'woocommerce' ),
),
),
)
);
$button_text_columns = $buy_button_section->add_block(
array(
'id' => 'product-button-text-columns',
'blockName' => 'core/columns',
'order' => 20,
)
);
$button_text_columns->add_block(
array(
'id' => 'product-button-text-column1',
'blockName' => 'core/column',
'order' => 10,
)
)->add_block(
array(
'id' => 'product-button-text',
'blockName' => 'woocommerce/product-text-field',
'order' => 10,
'attributes' => array(
'property' => 'button_text',
'label' => __( 'Buy button text', 'woocommerce' ),
),
)
);
$button_text_columns->add_block(
array(
'id' => 'product-button-text-column2',
'blockName' => 'core/column',
'order' => 20,
)
);
// Product list section.
$product_list_section = $general_group->add_section(
array(
'id' => 'product-list-section',
'order' => 35,
'attributes' => array(
'title' => __( 'Products in this group', 'woocommerce' ),
'description' => __( 'Make a collection of related products, enabling customers to purchase multiple items together.', 'woocommerce' ),
),
'hideConditions' => array(
array(
'expression' => 'editedProduct.type !== "grouped"',
),
),
)
);
$product_list_section->add_block(
array(
'id' => 'product-list',
'blockName' => 'woocommerce/product-list-field',
'order' => 10,
'attributes' => array(
'property' => 'grouped_products',
),
)
);
// Images section.
$images_section = $general_group->add_section(
array(
'id' => 'product-images-section',
'order' => 40,
'attributes' => array(
'title' => __( 'Images', 'woocommerce' ),
'description' => sprintf(
/* translators: %1$s: Images guide link opening tag. %2$s: Images guide link closing tag. */
__( 'Drag images, upload new ones or select files from your library. For best results, use JPEG files that are 1000 by 1000 pixels or larger. %1$sHow to prepare images?%2$s', 'woocommerce' ),
'<a href="https://woocommerce.com/posts/how-to-take-professional-product-photos-top-tips" target="_blank" rel="noreferrer">',
'</a>'
),
),
)
);
$images_section->add_block(
array(
'id' => 'product-images',
'blockName' => 'woocommerce/product-images-field',
'order' => 10,
'attributes' => array(
'images' => array(),
'property' => 'images',
),
)
);
// Downloads section.
$this->add_downloadable_product_blocks( $general_group );
}