Skip to content

Fix - WC()->cart null check missing on the centre-logo header layout - #113

Merged
iamprazol merged 2 commits into
developfrom
fix/83-header-cart-null-check
Sep 30, 2026
Merged

iamprazol merged 2 commits into
developfrom
fix/83-header-cart-null-check

Conversation

@rajatgautam755421

@rajatgautam755421 rajatgautam755421 commented Sep 28, 2026 •

Copy link
Copy Markdown

Closes themegrill/flash-pro#83

Summary

header.php has two near-identical "show the cart icon" blocks, one per header layout. Commit e485518 (2026-06-26) added isset( WC()->cart ) to the default (left-logo-right-menu) block, but never touched the second one, used for the center-logo-below-menu layout. WooCommerce leaves WC()->cart as null during 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's woocommerce_add_to_cart_fragments callback dereferences WC()->cart the 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.php twice, once per layout, with WC()->cart forced to null:

  • Against this branch: both layouts render cleanly, no fatal.
  • Against unpatched develop (same harness, only the file swapped): the center-logo-below-menu layout reproduces the exact fatal from the issue; left-logo-right-menu was 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

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>
@tg-autopilot
tg-autopilot requested a lite review from Copilot September 28, 2026 08:28
@github-actions

Copy link
Copy Markdown

QA suite — refused, no regression spec

This PR changes product source but adds no spec, so the suite was
refused before booting WordPress — running it just to report the same
thing at the end costs runner minutes for nothing. Run
/claudegrill:verify-fix locally and let write-spec add the guard
to this branch, then push again.

Source files changed with no matching spec
header.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@deepench

Copy link
Copy Markdown
Contributor

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>
@rajatgautam755421

Copy link
Copy Markdown
Author

@deepench Fixed in 0a313f9, same guard as flash-pro#125. Verified with the same forced-null harness: fatals on the original code, clean on the fix.

@deepench deepench left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@iamprazol iamprazol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !! 👍

@iamprazol
iamprazol merged commit 519a3e6 into develop Sep 30, 2026
1 check failed
@iamprazol
iamprazol deleted the fix/83-header-cart-null-check branch September 30, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants