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