Ensure we are loading product page gallery scripts in for FSE themes

This commit is contained in:
Tom Cafferkey 2021-11-08 17:26:46 +00:00
parent 5cdc6c86f6
commit c5e17812f0
2 changed files with 30 additions and 5 deletions

View File

@ -44,6 +44,11 @@ class WC_Template_Loader {
if ( self::$theme_support ) { if ( self::$theme_support ) {
add_filter( 'template_include', array( __CLASS__, 'template_loader' ) ); add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
add_filter( 'comments_template', array( __CLASS__, 'comments_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 { } else {
// Unsupported themes. // Unsupported themes.
add_action( 'template_redirect', array( __CLASS__, 'unsupported_theme_init' ) ); 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' ) ); 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_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 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-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' ); add_theme_support( 'wc-product-gallery-slider' );

View File

@ -495,6 +495,20 @@ function wc_is_file_valid_csv( $file, $check_path = true ) {
return false; 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. * 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 * @return bool
*/ */
function wc_current_theme_supports_woocommerce_or_fse() { function wc_current_theme_supports_woocommerce_or_fse() {
if ( function_exists( 'gutenberg_is_fse_theme' ) ) { return (bool) current_theme_supports( 'woocommerce' ) || wc_current_theme_is_fse_theme();
return (bool) current_theme_supports( 'woocommerce' ) || gutenberg_is_fse_theme();
}
return (bool) current_theme_supports( 'woocommerce' );
} }