Fix - Header cart count and total stale after AJAX add to cart - #143
rajatgautam755421 wants to merge 2 commits into
Conversation
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 <noreply@anthropic.com>
Regenerated with the makepot options from Gruntfile.js. Only the creation date and source line references change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
QA suite — refused, no regression specThis PR changes product source but adds no spec, so the suite was Source files changed with no matching spec |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Adjust fragment registration priority to preserve later-added fragments.
Review effort: Lite
Findings: None
What changed in this PR
Fixes stale WooCommerce header cart counts and totals after AJAX cart updates.
Changes:
- Adds reusable header cart rendering and WooCommerce fragment support.
- Preserves existing overrides and fragments.
- Regenerates translation references.
| File | Summary |
|---|---|
inc/header-functions.php |
Adds shared rendering and AJAX fragment synchronization; callback priority needs adjustment to prevent later providers from overwriting the fragment. |
languages/spacious.pot |
Updates generated translation metadata and source references. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@tg-autopilot review This ports the final, Copilot-approved version of themegrill/spacious-pro#189 to the free theme. Please review. |
|
Note on the first automated review ("adjust fragment registration priority to preserve later-added fragments"): no change needed. Plugins and child themes load before the parent theme's |


Changes proposed in this Pull Request:
Fixes the free-theme part of themegrill/spacious-pro#109 (the issue notes it is also present in the free theme). The same fix for Pro is themegrill/spacious-pro#189, already reviewed by Copilot with approval recommended; this PR ports that final version.
The header cart (item count and total) was rendered once at page load and never registered as a WooCommerce cart fragment. After an AJAX add to cart, WooCommerce refreshed its own mini-cart, but the header badge and total kept their old values until the page was reloaded.
The header cart block now lives in one function,
spacious_cart_icon_views(), used by both the initial render (spacious_cart_icon()) and a newwoocommerce_add_to_cart_fragmentsfilter (spacious_cart_icon_fragment()). Both new functions are wrapped infunction_exists()like the rest of the file.Effect on existing sites
spacious_cart_icon()is left exactly as it was.spacious_cart_icon()keeps its own markup: the fragment filter is registered together with the defaultspacious_cart_icon(), so it is not added when that function is overridden..cart-wrapperis left alone; WooCommerce keeps updating it itself.How to test the changes in this Pull Request:
Types of changes:
Other information:
Changelog entry
Fix - Header cart count and total now update right after an AJAX add to cart, without a page reload.
Verification (Spacious 1.9.12, WooCommerce, logged-in session)
div.widget_shopping_cart_content.div.spacious-woocommerce-cart-viewsfragment.spacious_cart_icon()the page renders the override and the theme sends no header fragment; a site's own fragment for the same selector is preserved.div.widget_shopping_cart_content.Totalstring changed its source line, solanguages/spacious.potwas regenerated with themakepotoptions fromGruntfile.js. The diff is only the creation date and source line references.inc/header-functions.php: no violations added or removed (42 errors and 8 warnings before and after, all in older code). PHPCompatibilityWP 7.4-: clean.🤖 Generated with Claude Code