diff --git a/plugins/woocommerce-blocks/src/BlockTemplatesController.php b/plugins/woocommerce-blocks/src/BlockTemplatesController.php index f0559ec586b..7538cea4e1f 100644 --- a/plugins/woocommerce-blocks/src/BlockTemplatesController.php +++ b/plugins/woocommerce-blocks/src/BlockTemplatesController.php @@ -42,8 +42,11 @@ class BlockTemplatesController { public function __construct( Package $package ) { $this->package = $package; + $feature_gating = $package->feature(); + $is_block_templates_controller_refactor_enabled = $feature_gating->is_block_templates_controller_refactor_enabled(); + // This feature is gated for WooCommerce versions 6.0.0 and above. - if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) ) { + if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) && ! $is_block_templates_controller_refactor_enabled ) { $this->init(); } } diff --git a/plugins/woocommerce-blocks/src/Domain/Services/FeatureGating.php b/plugins/woocommerce-blocks/src/Domain/Services/FeatureGating.php index 250187dc7e0..bfa5349d2cb 100644 --- a/plugins/woocommerce-blocks/src/Domain/Services/FeatureGating.php +++ b/plugins/woocommerce-blocks/src/Domain/Services/FeatureGating.php @@ -164,4 +164,15 @@ class FeatureGating { return self::EXPERIMENTAL_FLAG; } + + /** + * Check if the block templates controller refactor should be used to display blocks. + * + * @return boolean + */ + public function is_block_templates_controller_refactor_enabled() { + $conf = parse_ini_file( __DIR__ . '/../../../blocks.ini' ); + return $this->is_development_environment() && isset( $conf['use_block_templates_controller_refactor'] ) && true === (bool) $conf['use_block_templates_controller_refactor']; + } + }