Exercise 3: The Undefined WC_Cart Fatal Error — Possible Solution ==================================================================== THE LIKELY CAUSE ------------------------------ Per this chapter, this is the WooCommerce-specific timing gotcha named directly: "code that references WooCommerce's own classes or functions must not run before WooCommerce itself has finished loading - a fatal error results if a class like WC_Cart is referenced before it exists yet." The plugin's code is very likely running too early - before WooCommerce's own plugin has finished loading and defined its classes - which can happen depending on plugin load order. THE TWO FIXES THIS CHAPTER NAMES ------------------------------ Per this chapter, the two fixes are: 1. Wrapping the WooCommerce-dependent code inside a plugins_loaded hook, so it only runs after all active plugins (including WooCommerce) have finished loading. 2. Checking class_exists('WooCommerce') first, and only running the dependent code if that check passes. WHY THIS PROBLEM CAN APPEAR INTERMITTENTLY ------------------------------ Per this chapter, this failure mode "otherwise tends to appear intermittently depending on plugin load order" - meaning the exact same code might work or fail depending on the order plugins happen to load in, which is part of why it's worth guarding against explicitly rather than assuming a particular load order will always hold. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly identifies premature execution before WooCommerce has loaded as the cause, and correctly names both fixes this chapter specifically recommends, along with why the bug can appear inconsistently.