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

Commit

Permalink
Fix: Customizer fatal error for bundled woocommerce-blocks package (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhtungdu authored Apr 26, 2022
1 parent 0ecafd0 commit 1c0c69c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/BlockTypes/MiniCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 1c0c69c

Please sign in to comment.