diff --git a/README.txt b/README.txt index 4f7c0eb4..246c96e7 100644 --- a/README.txt +++ b/README.txt @@ -5,7 +5,7 @@ Tested up to: 6.2.2 Stable tag: 4.4.1 Version: 4.4.1 WC requires at least: 4.2 -WC tested up to: 7.7.0 +WC tested up to: 8.0.0 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html Tags: e-commerce, two-columns, left-sidebar, right-sidebar, custom-background, custom-colors, custom-header, custom-menu, featured-images, full-width-template, threaded-comments, accessibility-ready, rtl-language-support, footer-widgets, sticky-post, theme-options, editor-style diff --git a/inc/class-storefront.php b/inc/class-storefront.php index 31bd5a12..2640c364 100644 --- a/inc/class-storefront.php +++ b/inc/class-storefront.php @@ -32,6 +32,7 @@ if ( ! class_exists( 'Storefront' ) ) : add_filter( 'wp_page_menu_args', array( $this, 'page_menu_args' ) ); add_filter( 'navigation_markup_template', array( $this, 'navigation_markup_template' ) ); add_action( 'enqueue_embed_scripts', array( $this, 'print_embed_styles' ) ); + add_filter( 'woocommerce_get_script_data', array( $this, 'limit_cart_sync_to_wc_pages' ), 10, 2 ); } /** @@ -354,6 +355,8 @@ if ( ! class_exists( 'Storefront' ) ) : */ $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; + wp_enqueue_script( 'wc-cart-fragments' ); + wp_enqueue_script( 'storefront-navigation', get_template_directory_uri() . '/assets/js/navigation' . $suffix . '.js', array(), $storefront_version, true ); if ( has_nav_menu( 'handheld' ) ) { @@ -374,6 +377,24 @@ if ( ! class_exists( 'Storefront' ) ) : } } + /** + * Limit Cart Sync functionality to specific WooCommerce pages + * More details: https://developer.woocommerce.com/2023/06/16/best-practices-for-the-use-of-the-cart-fragments-api/ + * + * @param string $script_data The script data. + * @param string $handle The script handle. + * @return string|null + */ + public function limit_cart_sync_to_wc_pages( $script_data, $handle ) { + if ( 'wc-cart-fragments' === $handle ) { + if ( is_woocommerce() || is_cart() || is_checkout() ) { + return $script_data; + } + return null; + } + return $script_data; + } + /** * Register Google fonts. *