Merge pull request #31094 from woocommerce/update/current-theme-has-wc-or-fse-support
has_archive if current theme supports woocommerce or is an FSE theme
This commit is contained in:
commit
efdaf77d80
|
@ -299,14 +299,14 @@ class WC_Post_Types {
|
|||
|
||||
$shop_page_id = wc_get_page_id( 'shop' );
|
||||
|
||||
if ( current_theme_supports( 'woocommerce' ) ) {
|
||||
if ( wc_current_theme_supports_woocommerce_or_fse() ) {
|
||||
$has_archive = $shop_page_id && get_post( $shop_page_id ) ? urldecode( get_page_uri( $shop_page_id ) ) : 'shop';
|
||||
} else {
|
||||
$has_archive = false;
|
||||
}
|
||||
|
||||
// If theme support changes, we may need to flush permalinks since some are changed based on this flag.
|
||||
$theme_support = current_theme_supports( 'woocommerce' ) ? 'yes' : 'no';
|
||||
$theme_support = wc_current_theme_supports_woocommerce_or_fse() ? 'yes' : 'no';
|
||||
if ( get_option( 'current_theme_supports_woocommerce' ) !== $theme_support && update_option( 'current_theme_supports_woocommerce', $theme_support ) ) {
|
||||
update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
|
||||
}
|
||||
|
|
|
@ -37,13 +37,18 @@ class WC_Template_Loader {
|
|||
* Hook in methods.
|
||||
*/
|
||||
public static function init() {
|
||||
self::$theme_support = current_theme_supports( 'woocommerce' );
|
||||
self::$theme_support = wc_current_theme_supports_woocommerce_or_fse();
|
||||
self::$shop_page_id = wc_get_page_id( 'shop' );
|
||||
|
||||
// Supported themes.
|
||||
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' );
|
||||
|
|
|
@ -494,3 +494,28 @@ 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.
|
||||
*
|
||||
* @since x.x.x
|
||||
* @return bool
|
||||
*/
|
||||
function wc_current_theme_supports_woocommerce_or_fse() {
|
||||
return (bool) current_theme_supports( 'woocommerce' ) || wc_current_theme_is_fse_theme();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue