Enqueue wc-cart-fragments on woocommerce pages (#2113)

* enqueue wc-cart-fragments on woocommerce pages

* bump tested up version
This commit is contained in:
Luigi Teschio 2023-08-07 11:18:55 +02:00 committed by GitHub
parent bda638fe8f
commit b12b28a440
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -5,7 +5,7 @@ Tested up to: 6.2.2
Stable tag: 4.4.1 Stable tag: 4.4.1
Version: 4.4.1 Version: 4.4.1
WC requires at least: 4.2 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: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html 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 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

View file

@ -32,6 +32,7 @@ if ( ! class_exists( 'Storefront' ) ) :
add_filter( 'wp_page_menu_args', array( $this, 'page_menu_args' ) ); add_filter( 'wp_page_menu_args', array( $this, 'page_menu_args' ) );
add_filter( 'navigation_markup_template', array( $this, 'navigation_markup_template' ) ); add_filter( 'navigation_markup_template', array( $this, 'navigation_markup_template' ) );
add_action( 'enqueue_embed_scripts', array( $this, 'print_embed_styles' ) ); 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'; $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 ); wp_enqueue_script( 'storefront-navigation', get_template_directory_uri() . '/assets/js/navigation' . $suffix . '.js', array(), $storefront_version, true );
if ( has_nav_menu( 'handheld' ) ) { 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. * Register Google fonts.
* *