Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Blocks/Template...
File: ClassicTemplatesCompatibility.php
<?php
[0] Fix | Delete
namespace Automattic\WooCommerce\Blocks\Templates;
[1] Fix | Delete
[2] Fix | Delete
use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;
[3] Fix | Delete
[4] Fix | Delete
/**
[5] Fix | Delete
* ClassicTemplatesCompatibility class.
[6] Fix | Delete
*
[7] Fix | Delete
* To bridge the gap on compatibility with widget blocks and classic PHP core templates.
[8] Fix | Delete
*
[9] Fix | Delete
* @internal
[10] Fix | Delete
*/
[11] Fix | Delete
class ClassicTemplatesCompatibility {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Instance of the asset data registry.
[15] Fix | Delete
*
[16] Fix | Delete
* @var AssetDataRegistry
[17] Fix | Delete
*/
[18] Fix | Delete
protected $asset_data_registry;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Constructor.
[22] Fix | Delete
*
[23] Fix | Delete
* @param AssetDataRegistry $asset_data_registry Instance of the asset data registry.
[24] Fix | Delete
*/
[25] Fix | Delete
public function __construct( AssetDataRegistry $asset_data_registry ) {
[26] Fix | Delete
$this->asset_data_registry = $asset_data_registry;
[27] Fix | Delete
$this->init();
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Initialization method.
[32] Fix | Delete
*/
[33] Fix | Delete
protected function init() { // phpcs:ignore WooCommerce.Functions.InternalInjectionMethod.MissingPublic
[34] Fix | Delete
if ( ! wp_is_block_theme() ) {
[35] Fix | Delete
add_action( 'template_redirect', array( $this, 'set_classic_template_data' ) );
[36] Fix | Delete
// We need to set this data on the widgets screen so the filters render previews.
[37] Fix | Delete
add_action( 'load-widgets.php', array( $this, 'set_filterable_product_data' ) );
[38] Fix | Delete
}
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Executes the methods which set the necessary data needed for filter blocks to work correctly as widgets in Classic templates.
[43] Fix | Delete
*
[44] Fix | Delete
* @return void
[45] Fix | Delete
*/
[46] Fix | Delete
public function set_classic_template_data() {
[47] Fix | Delete
$this->set_filterable_product_data();
[48] Fix | Delete
$this->set_php_template_data();
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* This method passes the value `has_filterable_products` to the front-end for product archive pages,
[53] Fix | Delete
* so that widget product filter blocks are aware of the context they are in and can render accordingly.
[54] Fix | Delete
*
[55] Fix | Delete
* @return void
[56] Fix | Delete
*/
[57] Fix | Delete
public function set_filterable_product_data() {
[58] Fix | Delete
global $pagenow;
[59] Fix | Delete
[60] Fix | Delete
if ( is_shop() || is_product_taxonomy() || 'widgets.php' === $pagenow ) {
[61] Fix | Delete
$this->asset_data_registry->add( 'hasFilterableProducts', true );
[62] Fix | Delete
}
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* This method passes the value `is_rendering_php_template` to the front-end of Classic themes,
[67] Fix | Delete
* so that widget product filter blocks are aware of how to filter the products.
[68] Fix | Delete
*
[69] Fix | Delete
* This data only matters on WooCommerce product archive pages.
[70] Fix | Delete
* On non-archive pages the merchant could be using the All Products block which is not a PHP template.
[71] Fix | Delete
*
[72] Fix | Delete
* @return void
[73] Fix | Delete
*/
[74] Fix | Delete
public function set_php_template_data() {
[75] Fix | Delete
if ( is_shop() || is_product_taxonomy() ) {
[76] Fix | Delete
$this->asset_data_registry->add( 'isRenderingPhpTemplate', true );
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function