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

Fix required scripts not loading for WC block templates. #5346

Merged
merged 1 commit into from
Dec 10, 2021
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
8 changes: 8 additions & 0 deletions src/BlockTypes/LegacyTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ protected function render( $attributes, $content ) {
return;
}

// We need to load the scripts here because when using block templates wp_head() gets run after the block template.
// As a result we are trying to enqueue required scripts before we have even registered them.
// See here for more information: https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5328#issuecomment-989013447.
if ( class_exists( 'WC_Frontend_Scripts' ) ) {
$frontend_scripts = new \WC_Frontend_Scripts();
$frontend_scripts::load_scripts();
}

$archive_templates = array( 'archive-product', 'taxonomy-product_cat', 'taxonomy-product_tag' );

if ( 'single-product' === $attributes['template'] ) {
Expand Down