diff --git a/inc/header-functions.php b/inc/header-functions.php index 83f2945e..8cddb63f 100644 --- a/inc/header-functions.php +++ b/inc/header-functions.php @@ -81,22 +81,7 @@ function spacious_cart_icon() { if ( ( get_theme_mod( 'spacious_cart_icon', 0 ) == 1 ) && class_exists( 'woocommerce' ) ) : ?>
-
- - - cart->get_cart_url(); ?> - - - - cart->get_cart_contents_count() ); ?> - - - -
-
-
cart->get_cart_subtotal() ); ?>
-
-
+ @@ -106,6 +91,114 @@ function spacious_cart_icon() { endif; } + // Registered with the default renderer, so a child theme overriding spacious_cart_icon() keeps its own markup. + add_filter( 'woocommerce_add_to_cart_fragments', 'spacious_cart_icon_fragment' ); + add_action( 'wp_enqueue_scripts', 'spacious_cart_icon_scripts' ); + +endif; + +if ( ! function_exists( 'spacious_cart_icon_views' ) ) : + + /** + * Output the header cart icon, item count and total. + * + * Shared by the initial render and the WooCommerce cart fragment so both stay identical. + */ + function spacious_cart_icon_views() { + $cart_url = function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : WC()->cart->get_cart_url(); + ?> +
+ + + + + + cart->get_cart_contents_count() ); ?> + + + +
+
+
cart->get_cart_subtotal() ); ?>
+
+
+ cart ) || isset( $fragments[ $selector ] ) ) { + return $fragments; + } + + ob_start(); + spacious_cart_icon_views(); + $fragments[ $selector ] = ob_get_clean(); + + return $fragments; + } + +endif; + +if ( ! function_exists( 'spacious_cart_icon_scripts' ) ) : + + /** + * Load what keeps the header cart icon in sync on the Cart and Checkout pages. + * + * The WooCommerce cart widget, which normally loads cart fragments, hides itself on those pages, + * and the Cart and Checkout blocks change the cart without firing the events cart fragments listen for. + */ + function spacious_cart_icon_scripts() { + if ( 1 !== (int) get_theme_mod( 'spacious_cart_icon', 0 ) || ! class_exists( 'woocommerce' ) ) { + return; + } + + wp_enqueue_script( 'wc-cart-fragments' ); + + // Printed only where the blocks load their cart store. + wp_add_inline_script( + 'wc-blocks-data-store', + "( function () { + var cart = window.wp && wp.data && wp.data.select( 'wc/store/cart' ); + + if ( ! cart ) { + return; + } + + function key() { + var data = cart.getCartData(); + + return data.itemsCount + '|' + data.totals.total_items; + } + + var last = key(); + + wp.data.subscribe( function () { + var now = key(); + + if ( now !== last && window.jQuery ) { + jQuery( document.body ).trigger( 'wc_fragment_refresh' ); + } + + last = now; + } ); + } )();" + ); + } + endif; /****************************************************************************************/ diff --git a/languages/spacious.pot b/languages/spacious.pot index c0b826f1..2b27b92e 100644 --- a/languages/spacious.pot +++ b/languages/spacious.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Spacious 1.9.12\n" "Report-Msgid-Bugs-To: themegrill@gmail.com\n" -"POT-Creation-Date: 2026-09-18 11:47:31+00:00\n" +"POT-Creation-Date: 2026-09-28 06:56:32+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -187,7 +187,7 @@ msgstr "" #: functions.php:324 functions.php:329 #: inc/customizer/class-spacious-customizer-partials.php:30 -#: inc/functions.php:662 inc/header-functions.php:166 +#: inc/functions.php:662 inc/header-functions.php:259 #: inc/widgets/class-spacious-featured-single-page-widget.php:104 #: inc/widgets/class-spacious-service-widget.php:48 #: inc/widgets/class-spacious-service-widget.php:74 @@ -421,7 +421,7 @@ msgstr "" #: inc/customizer/class-spacious-customizer-partials.php:49 #: inc/customizer/class-spacious-customizer-partials.php:56 -#: inc/header-functions.php:314 inc/header-functions.php:320 +#: inc/header-functions.php:407 inc/header-functions.php:413 msgid "You are here: " msgstr "" @@ -1447,59 +1447,59 @@ msgstr "" msgid "Comments Off" msgstr "" -#: inc/header-functions.php:96 +#: inc/header-functions.php:121 msgid "Total" msgstr "" -#: inc/header-functions.php:244 +#: inc/header-functions.php:337 msgid "Author: %s" msgstr "" -#: inc/header-functions.php:252 +#: inc/header-functions.php:345 msgid "Day: %s" msgstr "" -#: inc/header-functions.php:255 +#: inc/header-functions.php:348 msgid "Month: %s" msgstr "" -#: inc/header-functions.php:258 +#: inc/header-functions.php:351 msgid "Year: %s" msgstr "" -#: inc/header-functions.php:261 +#: inc/header-functions.php:354 msgid "Asides" msgstr "" -#: inc/header-functions.php:264 +#: inc/header-functions.php:357 msgid "Images" msgstr "" -#: inc/header-functions.php:267 +#: inc/header-functions.php:360 msgid "Videos" msgstr "" -#: inc/header-functions.php:270 +#: inc/header-functions.php:363 msgid "Quotes" msgstr "" -#: inc/header-functions.php:273 +#: inc/header-functions.php:366 msgid "Links" msgstr "" -#: inc/header-functions.php:279 sidebar-left.php:29 sidebar.php:32 +#: inc/header-functions.php:372 sidebar-left.php:29 sidebar.php:32 msgid "Archives" msgstr "" -#: inc/header-functions.php:283 +#: inc/header-functions.php:376 msgid "Page NOT Found" msgstr "" -#: inc/header-functions.php:285 +#: inc/header-functions.php:378 msgid "Search Results" msgstr "" -#: inc/header-functions.php:341 +#: inc/header-functions.php:434 msgid "Menu" msgstr ""