Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Blocks
File: BlockTemplatesRegistry.php
<?php
[0] Fix | Delete
namespace Automattic\WooCommerce\Blocks;
[1] Fix | Delete
[2] Fix | Delete
use Automattic\WooCommerce\Admin\Features\Features;
[3] Fix | Delete
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;
[4] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\AbstractTemplate;
[5] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\AbstractTemplatePart;
[6] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\MiniCartTemplate;
[7] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\CartTemplate;
[8] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\CheckoutTemplate;
[9] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\CheckoutHeaderTemplate;
[10] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\ComingSoonTemplate;
[11] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\OrderConfirmationTemplate;
[12] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\ProductAttributeTemplate;
[13] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\ProductBrandTemplate;
[14] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\ProductCatalogTemplate;
[15] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\ProductCategoryTemplate;
[16] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\ProductTagTemplate;
[17] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\ProductSearchResultsTemplate;
[18] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplate;
[19] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\SimpleProductAddToCartWithOptionsTemplate;
[20] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\ExternalProductAddToCartWithOptionsTemplate;
[21] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\VariableProductAddToCartWithOptionsTemplate;
[22] Fix | Delete
use Automattic\WooCommerce\Blocks\Templates\GroupedProductAddToCartWithOptionsTemplate;
[23] Fix | Delete
use Automattic\WooCommerce\Enums\ProductType;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* BlockTemplatesRegistry class.
[27] Fix | Delete
*
[28] Fix | Delete
* @internal
[29] Fix | Delete
*/
[30] Fix | Delete
class BlockTemplatesRegistry {
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* The array of registered templates.
[34] Fix | Delete
*
[35] Fix | Delete
* @var AbstractTemplate[]|AbstractTemplatePart[]
[36] Fix | Delete
*/
[37] Fix | Delete
private $templates = array();
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Initialization method.
[41] Fix | Delete
*/
[42] Fix | Delete
public function init() {
[43] Fix | Delete
if ( BlockTemplateUtils::supports_block_templates( 'wp_template' ) ) {
[44] Fix | Delete
$templates = array(
[45] Fix | Delete
ProductCatalogTemplate::SLUG => new ProductCatalogTemplate(),
[46] Fix | Delete
ProductCategoryTemplate::SLUG => new ProductCategoryTemplate(),
[47] Fix | Delete
ProductTagTemplate::SLUG => new ProductTagTemplate(),
[48] Fix | Delete
ProductAttributeTemplate::SLUG => new ProductAttributeTemplate(),
[49] Fix | Delete
ProductBrandTemplate::SLUG => new ProductBrandTemplate(),
[50] Fix | Delete
ProductSearchResultsTemplate::SLUG => new ProductSearchResultsTemplate(),
[51] Fix | Delete
CartTemplate::SLUG => new CartTemplate(),
[52] Fix | Delete
CheckoutTemplate::SLUG => new CheckoutTemplate(),
[53] Fix | Delete
OrderConfirmationTemplate::SLUG => new OrderConfirmationTemplate(),
[54] Fix | Delete
SingleProductTemplate::SLUG => new SingleProductTemplate(),
[55] Fix | Delete
);
[56] Fix | Delete
} else {
[57] Fix | Delete
$templates = array();
[58] Fix | Delete
}
[59] Fix | Delete
if ( Features::is_enabled( 'launch-your-store' ) ) {
[60] Fix | Delete
$templates[ ComingSoonTemplate::SLUG ] = new ComingSoonTemplate();
[61] Fix | Delete
}
[62] Fix | Delete
if ( BlockTemplateUtils::supports_block_templates( 'wp_template_part' ) ) {
[63] Fix | Delete
$template_parts = array(
[64] Fix | Delete
MiniCartTemplate::SLUG => new MiniCartTemplate(),
[65] Fix | Delete
CheckoutHeaderTemplate::SLUG => new CheckoutHeaderTemplate(),
[66] Fix | Delete
);
[67] Fix | Delete
if ( wp_is_block_theme() ) {
[68] Fix | Delete
$product_types = wc_get_product_types();
[69] Fix | Delete
if ( count( $product_types ) > 0 ) {
[70] Fix | Delete
add_filter( 'default_wp_template_part_areas', array( $this, 'register_add_to_cart_with_options_template_part_area' ), 10, 1 );
[71] Fix | Delete
if ( array_key_exists( ProductType::SIMPLE, $product_types ) ) {
[72] Fix | Delete
$template_parts[ SimpleProductAddToCartWithOptionsTemplate::SLUG ] = new SimpleProductAddToCartWithOptionsTemplate();
[73] Fix | Delete
}
[74] Fix | Delete
if ( array_key_exists( ProductType::EXTERNAL, $product_types ) ) {
[75] Fix | Delete
$template_parts[ ExternalProductAddToCartWithOptionsTemplate::SLUG ] = new ExternalProductAddToCartWithOptionsTemplate();
[76] Fix | Delete
}
[77] Fix | Delete
if ( array_key_exists( ProductType::VARIABLE, $product_types ) ) {
[78] Fix | Delete
$template_parts[ VariableProductAddToCartWithOptionsTemplate::SLUG ] = new VariableProductAddToCartWithOptionsTemplate();
[79] Fix | Delete
}
[80] Fix | Delete
if ( array_key_exists( ProductType::GROUPED, $product_types ) ) {
[81] Fix | Delete
$template_parts[ GroupedProductAddToCartWithOptionsTemplate::SLUG ] = new GroupedProductAddToCartWithOptionsTemplate();
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
}
[85] Fix | Delete
} else {
[86] Fix | Delete
$template_parts = array();
[87] Fix | Delete
}
[88] Fix | Delete
$this->templates = array_merge( $templates, $template_parts );
[89] Fix | Delete
[90] Fix | Delete
// Init all templates.
[91] Fix | Delete
foreach ( $this->templates as $template ) {
[92] Fix | Delete
$template->init();
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Add Add to Cart + Options to the default template part areas.
[98] Fix | Delete
*
[99] Fix | Delete
* @param array $default_area_definitions An array of supported area objects.
[100] Fix | Delete
* @return array The supported template part areas including the Add to Cart + Options one.
[101] Fix | Delete
*/
[102] Fix | Delete
public function register_add_to_cart_with_options_template_part_area( $default_area_definitions ) {
[103] Fix | Delete
$add_to_cart_with_options_template_part_area = array(
[104] Fix | Delete
'area' => 'add-to-cart-with-options',
[105] Fix | Delete
'label' => __( 'Add to Cart + Options', 'woocommerce' ),
[106] Fix | Delete
'description' => __( 'The Add to Cart + Options templates allow defining a different layout for each product type.', 'woocommerce' ),
[107] Fix | Delete
'icon' => 'add-to-cart-with-options',
[108] Fix | Delete
'area_tag' => 'add-to-cart-with-options',
[109] Fix | Delete
);
[110] Fix | Delete
return array_merge( $default_area_definitions, array( $add_to_cart_with_options_template_part_area ) );
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Returns the template matching the slug
[115] Fix | Delete
*
[116] Fix | Delete
* @param string $template_slug Slug of the template to retrieve.
[117] Fix | Delete
*
[118] Fix | Delete
* @return AbstractTemplate|AbstractTemplatePart|null
[119] Fix | Delete
*/
[120] Fix | Delete
public function get_template( $template_slug ) {
[121] Fix | Delete
if ( array_key_exists( $template_slug, $this->templates ) ) {
[122] Fix | Delete
$registered_template = $this->templates[ $template_slug ];
[123] Fix | Delete
return $registered_template;
[124] Fix | Delete
}
[125] Fix | Delete
return null;
[126] Fix | Delete
}
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function