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

Fix: Customizer fatal error for bundled woocommerce-blocks package #6317

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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