Fix - WC()->cart null check missing on the centre-logo header layout - #113
Conversation
e485518 added `isset( WC()->cart )` to header.php's default cart block, but the theme has a second, near-identical cart block for the center-logo-below-menu layout that was never touched. Any WooCommerce site using that layout still fataled on WC()->cart->get_cart_contents_count() whenever WC()->cart was null (REST requests, other non-frontend renders). Verified with both header.php cart blocks rendered directly, WC()->cart forced null: the unpatched block fatals as expected, the patched one (this commit) doesn't, for both header layouts. See themegrill/flash-pro#83. Co-Authored-By: Claude Sonnet 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
🟢 Approval recommended
The targeted fix is complete and verified.
Review effort: Lite
Findings: None
What changed in this PR
Adds the missing WooCommerce cart null check for the center-logo header layout, preventing fatals when the cart is unavailable.
Changes:
- Guards cart rendering with
isset( WC()->cart ). - Aligns both header layouts’ cart checks.
| File | Description |
|---|---|
header.php |
Adds the cart availability guard to the center-logo layout. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Verified this fix works — forced WC()->cart null on the center-logo-below-menu layout and it fatals before, doesn't after. Same issue is still open in inc/woocommerce.php:46 (flash_woocommerce_header_add_to_cart_fragment) - the PR says it's safe because it only fires during WooCommerce's own AJAX flow where cart is guaranteed to exist, but I tested that assumption directly and it doesn't hold: forcing WC()->cart null into the woocommerce_add_to_cart_fragments filter reproduces the exact same fatal there. Same gap as flash-pro#125. |
flash_woocommerce_header_add_to_cart_fragment() (inc/woocommerce.php) has the identical unguarded WC()->cart access this PR fixed elsewhere, and fatals the same way when the cart isn't initialised - confirmed live by forcing WC()->cart null into the woocommerce_add_to_cart_fragments filter. Early-returns the fragments array unchanged when the cart isn't available, same guard condition as the other fix. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Closes themegrill/flash-pro#83
Summary
header.phphas two near-identical "show the cart icon" blocks, one per header layout. Commite485518(2026-06-26) addedisset( WC()->cart )to the default (left-logo-right-menu) block, but never touched the second one, used for thecenter-logo-below-menulayout. WooCommerce leavesWC()->cartasnullduring REST requests and other non-frontend renders, so any request that renders the header on that layout still fatals:Call to a member function get_cart_contents_count() on null.This adds the same guard to the remaining block.
inc/woocommerce.php'swoocommerce_add_to_cart_fragmentscallback dereferencesWC()->cartthe same way, but is left untouched — it only fires during WooCommerce's own AJAX add-to-cart flow, where the cart is guaranteed to exist.Testing
Rendered the real
header.phptwice, once per layout, withWC()->cartforced tonull:develop(same harness, only the file swapped): thecenter-logo-below-menulayout reproduces the exact fatal from the issue;left-logo-right-menuwas already fine, confirming the harness isn't a false pass.Closes #83 for this repo (Pro's half is themegrill/flash-pro#83 itself, and gets its own PR).
🤖 Generated with Claude Code