From 2da9079003855a862043540025ec2b8fa73c0ca8 Mon Sep 17 00:00:00 2001 From: Tung Du Date: Tue, 26 Apr 2022 15:21:14 +0700 Subject: [PATCH] Fix: Customizer fatal error for bundled woocommerce-blocks package (#6317) --- src/BlockTypes/MiniCart.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/BlockTypes/MiniCart.php b/src/BlockTypes/MiniCart.php index 91c222f8f7c..2364c4b2c6a 100644 --- a/src/BlockTypes/MiniCart.php +++ b/src/BlockTypes/MiniCart.php @@ -150,8 +150,14 @@ protected function enqueue_data( array $attributes = [] ) { * * $wp_scripts->print_translations() calls load_script_textdomain() * which calls load_script_translations() containing the below filter. + * + * In Customzier, woocommerce_blocks_get_i18n_data_json doesn't exist + * at the time of this filter call. So we need checking for its + * existence to prevent fatal error. */ - remove_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 ); + if ( function_exists( 'woocommerce_blocks_get_i18n_data_json' ) ) { + remove_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 ); + } $script_data = $this->asset_api->get_script_data( 'build/mini-cart-component-frontend.js' ); @@ -187,7 +193,9 @@ protected function enqueue_data( array $attributes = [] ) { ); // Re-add the filter. - add_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 ); + if ( function_exists( 'woocommerce_blocks_get_i18n_data_json' ) ) { + add_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 ); + } $this->asset_data_registry->add( 'mini_cart_block_frontend_dependencies',