From c5e17812f0f8847e2594be8a6b5880265c0a9d1b Mon Sep 17 00:00:00 2001 From: Tom Cafferkey Date: Mon, 8 Nov 2021 17:26:46 +0000 Subject: [PATCH] Ensure we are loading product page gallery scripts in for FSE themes --- .../includes/class-wc-template-loader.php | 14 +++++++++++++ .../includes/wc-conditional-functions.php | 21 ++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/plugins/woocommerce/includes/class-wc-template-loader.php b/plugins/woocommerce/includes/class-wc-template-loader.php index 766108dac96..d8c1182c931 100644 --- a/plugins/woocommerce/includes/class-wc-template-loader.php +++ b/plugins/woocommerce/includes/class-wc-template-loader.php @@ -44,6 +44,11 @@ class WC_Template_Loader { if ( self::$theme_support ) { add_filter( 'template_include', array( __CLASS__, 'template_loader' ) ); add_filter( 'comments_template', array( __CLASS__, 'comments_template_loader' ) ); + + // Loads gallery scripts on Product page for FSE themes. + if ( wc_current_theme_is_fse_theme() ) { + self::add_support_for_product_page_gallery(); + } } else { // Unsupported themes. add_action( 'template_redirect', array( __CLASS__, 'unsupported_theme_init' ) ); @@ -292,6 +297,15 @@ class WC_Template_Loader { add_filter( 'woocommerce_product_tabs', array( __CLASS__, 'unsupported_theme_remove_review_tab' ) ); remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); + self::add_support_for_product_page_gallery(); + } + + /** + * Add theme support for Product page gallery. + * + * @since x.x.x + */ + private static function add_support_for_product_page_gallery() { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); diff --git a/plugins/woocommerce/includes/wc-conditional-functions.php b/plugins/woocommerce/includes/wc-conditional-functions.php index 1ce15a472c7..bdebe59dc48 100644 --- a/plugins/woocommerce/includes/wc-conditional-functions.php +++ b/plugins/woocommerce/includes/wc-conditional-functions.php @@ -495,6 +495,20 @@ function wc_is_file_valid_csv( $file, $check_path = true ) { return false; } +/** + * Check if the current theme is an FSE theme. + * + * @since x.x.x + * @return bool + */ +function wc_current_theme_is_fse_theme() { + if ( function_exists( 'gutenberg_is_fse_theme' ) ) { + return (bool) gutenberg_is_fse_theme(); + } + + return false; +} + /** * Check if the current theme has WooCommerce support or is a FSE theme. * @@ -502,9 +516,6 @@ function wc_is_file_valid_csv( $file, $check_path = true ) { * @return bool */ function wc_current_theme_supports_woocommerce_or_fse() { - if ( function_exists( 'gutenberg_is_fse_theme' ) ) { - return (bool) current_theme_supports( 'woocommerce' ) || gutenberg_is_fse_theme(); - } - - return (bool) current_theme_supports( 'woocommerce' ); + return (bool) current_theme_supports( 'woocommerce' ) || wc_current_theme_is_fse_theme(); } +