mirror of
https://github.com/woocommerce/storefront.git
synced 2025-08-20 04:00:29 +08:00
Enqueue wc-cart-fragments on woocommerce pages (#2113)
* enqueue wc-cart-fragments on woocommerce pages * bump tested up version
This commit is contained in:
parent
bda638fe8f
commit
b12b28a440
2 changed files with 22 additions and 1 deletions
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue