From 3cdc0fcc07f493ee309234f1175dc939f7cebc6e Mon Sep 17 00:00:00 2001 From: rg755421 Date: Fri, 25 Sep 2026 10:25:37 +0545 Subject: [PATCH 1/3] Fix - Header cart count and total stayed stale after AJAX add to cart The header cart block was rendered once at page load and never registered as a WooCommerce cart fragment, so it only refreshed on a full reload while the mini-cart updated. Move the block into a shared function used by both the initial render and a woocommerce_add_to_cart_fragments filter. The filter is registered with the default spacious_cart_icon(), so a child theme overriding it keeps its own markup, and it never overwrites a fragment already supplied for the same selector. Co-Authored-By: Claude Opus 5.5 --- inc/header-functions.php | 76 +++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/inc/header-functions.php b/inc/header-functions.php index 83f2945e..d5f8ca74 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,65 @@ 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' ); + +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; /****************************************************************************************/ From f6c1481b12f6740095d10105576fd96d74f8b1c9 Mon Sep 17 00:00:00 2001 From: rg755421 Date: Fri, 25 Sep 2026 10:25:37 +0545 Subject: [PATCH 2/3] Update translation template after moving the header cart strings Regenerated with the makepot options from Gruntfile.js. Only the creation date and source line references change. Co-Authored-By: Claude Opus 5.5 --- languages/spacious.pot | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/languages/spacious.pot b/languages/spacious.pot index c0b826f1..55389f7b 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-25 04:40:00+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:210 #: 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:358 inc/header-functions.php:364 msgid "You are here: " msgstr "" @@ -1447,59 +1447,59 @@ msgstr "" msgid "Comments Off" msgstr "" -#: inc/header-functions.php:96 +#: inc/header-functions.php:120 msgid "Total" msgstr "" -#: inc/header-functions.php:244 +#: inc/header-functions.php:288 msgid "Author: %s" msgstr "" -#: inc/header-functions.php:252 +#: inc/header-functions.php:296 msgid "Day: %s" msgstr "" -#: inc/header-functions.php:255 +#: inc/header-functions.php:299 msgid "Month: %s" msgstr "" -#: inc/header-functions.php:258 +#: inc/header-functions.php:302 msgid "Year: %s" msgstr "" -#: inc/header-functions.php:261 +#: inc/header-functions.php:305 msgid "Asides" msgstr "" -#: inc/header-functions.php:264 +#: inc/header-functions.php:308 msgid "Images" msgstr "" -#: inc/header-functions.php:267 +#: inc/header-functions.php:311 msgid "Videos" msgstr "" -#: inc/header-functions.php:270 +#: inc/header-functions.php:314 msgid "Quotes" msgstr "" -#: inc/header-functions.php:273 +#: inc/header-functions.php:317 msgid "Links" msgstr "" -#: inc/header-functions.php:279 sidebar-left.php:29 sidebar.php:32 +#: inc/header-functions.php:323 sidebar-left.php:29 sidebar.php:32 msgid "Archives" msgstr "" -#: inc/header-functions.php:283 +#: inc/header-functions.php:327 msgid "Page NOT Found" msgstr "" -#: inc/header-functions.php:285 +#: inc/header-functions.php:329 msgid "Search Results" msgstr "" -#: inc/header-functions.php:341 +#: inc/header-functions.php:385 msgid "Menu" msgstr "" From 57bb7ab02e9dd4e269e07364042099414f24241e Mon Sep 17 00:00:00 2001 From: rg755421 Date: Mon, 28 Sep 2026 12:41:43 +0545 Subject: [PATCH 3/3] Fix - Update the header cart on the Cart and Checkout pages The WooCommerce cart widget, which normally loads cart fragments, hides itself on the Cart and Checkout pages, so the header cart never refreshed there. The Cart and Checkout blocks also change the cart through the Store API without firing the events cart fragments listen for. Load cart fragments whenever the header cart icon is on, and when the Cart or Checkout block's cart store changes its item count or subtotal, trigger a fragment refresh so the header is re-rendered by spacious_cart_icon_views(). Co-Authored-By: Claude Opus 5.5 (1M context) --- inc/header-functions.php | 49 ++++++++++++++++++++++++++++++++++++++++ languages/spacious.pot | 34 ++++++++++++++-------------- 2 files changed, 66 insertions(+), 17 deletions(-) diff --git a/inc/header-functions.php b/inc/header-functions.php index d5f8ca74..8cddb63f 100644 --- a/inc/header-functions.php +++ b/inc/header-functions.php @@ -93,6 +93,7 @@ function spacious_cart_icon() { // 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; @@ -152,6 +153,54 @@ function spacious_cart_icon_fragment( $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; + /****************************************************************************************/ // Filter the get_header_image_tag() for supporting the older way of displaying the header image function spacious_header_image_markup( $html, $header, $attr ) { diff --git a/languages/spacious.pot b/languages/spacious.pot index 55389f7b..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-25 04:40:00+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:210 +#: 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:358 inc/header-functions.php:364 +#: 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:120 +#: inc/header-functions.php:121 msgid "Total" msgstr "" -#: inc/header-functions.php:288 +#: inc/header-functions.php:337 msgid "Author: %s" msgstr "" -#: inc/header-functions.php:296 +#: inc/header-functions.php:345 msgid "Day: %s" msgstr "" -#: inc/header-functions.php:299 +#: inc/header-functions.php:348 msgid "Month: %s" msgstr "" -#: inc/header-functions.php:302 +#: inc/header-functions.php:351 msgid "Year: %s" msgstr "" -#: inc/header-functions.php:305 +#: inc/header-functions.php:354 msgid "Asides" msgstr "" -#: inc/header-functions.php:308 +#: inc/header-functions.php:357 msgid "Images" msgstr "" -#: inc/header-functions.php:311 +#: inc/header-functions.php:360 msgid "Videos" msgstr "" -#: inc/header-functions.php:314 +#: inc/header-functions.php:363 msgid "Quotes" msgstr "" -#: inc/header-functions.php:317 +#: inc/header-functions.php:366 msgid "Links" msgstr "" -#: inc/header-functions.php:323 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:327 +#: inc/header-functions.php:376 msgid "Page NOT Found" msgstr "" -#: inc/header-functions.php:329 +#: inc/header-functions.php:378 msgid "Search Results" msgstr "" -#: inc/header-functions.php:385 +#: inc/header-functions.php:434 msgid "Menu" msgstr ""