Skip to content

Conversation

@eherman-godaddy
Copy link
Contributor

This is a bit of an edge case, and a strange one, but one that I caught while testing out other things with the REST API.

When using the default permalinks, and you have an empty cart, the site will fatal error because $woocommerce->cart isn't available. This PR just adds a check to make sure it's available for use before we actually use it.

Permalinks: Plain
URL: /wp-json/wp/v2/posts/

image

@eherman-godaddy eherman-godaddy self-assigned this Sep 18, 2025
@eherman-godaddy eherman-godaddy added [Type] Bug Something that is not working as expected [Type] Woo Relevant to WooCommerce labels Sep 18, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a WooCommerce fatal error that occurs when using default permalinks with an empty cart when accessing the REST API. The issue arises because $woocommerce->cart may not be available in certain contexts.

  • Adds a null check for $woocommerce->cart before accessing its methods
  • Prevents fatal errors when the cart object is not initialized during REST API requests

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@eherman-godaddy eherman-godaddy added this to the 1.8.18 milestone Sep 18, 2025
@eherman-godaddy eherman-godaddy merged commit bf72c6f into master Sep 22, 2025
9 checks passed
@eherman-godaddy eherman-godaddy deleted the fix-woocommerce-fatal branch September 22, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug Something that is not working as expected [Type] Woo Relevant to WooCommerce

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants