Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 2da9079

Browse files
dinhtungduTarun Vijwani
authored andcommitted
Fix: Customizer fatal error for bundled woocommerce-blocks package (#6317)
1 parent 432a3ed commit 2da9079

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/BlockTypes/MiniCart.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,14 @@ protected function enqueue_data( array $attributes = [] ) {
150150
*
151151
* $wp_scripts->print_translations() calls load_script_textdomain()
152152
* which calls load_script_translations() containing the below filter.
153+
*
154+
* In Customzier, woocommerce_blocks_get_i18n_data_json doesn't exist
155+
* at the time of this filter call. So we need checking for its
156+
* existence to prevent fatal error.
153157
*/
154-
remove_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 );
158+
if ( function_exists( 'woocommerce_blocks_get_i18n_data_json' ) ) {
159+
remove_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 );
160+
}
155161

156162
$script_data = $this->asset_api->get_script_data( 'build/mini-cart-component-frontend.js' );
157163

@@ -187,7 +193,9 @@ protected function enqueue_data( array $attributes = [] ) {
187193
);
188194

189195
// Re-add the filter.
190-
add_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 );
196+
if ( function_exists( 'woocommerce_blocks_get_i18n_data_json' ) ) {
197+
add_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 );
198+
}
191199

192200
$this->asset_data_registry->add(
193201
'mini_cart_block_frontend_dependencies',

0 commit comments

Comments
 (0)