Commit 4abffa2a39 for woocommerce

commit 4abffa2a3910d5201b3cbe362729ed569dcb7d67
Author: Herman <KokkieH@users.noreply.github.com>
Date:   Mon Jan 5 14:41:19 2026 +0200

    Check cart exists before trying to access it (#62644)

    * Check cart exists before trying to access it

    * Add changefile(s) from automation for the following project(s): woocommerce

    ---------

    Co-authored-by: github-actions <github-actions@github.com>

diff --git a/plugins/woocommerce/changelog/62644-fix-WCCOM-2096-fatal-when-cart-not-initialized b/plugins/woocommerce/changelog/62644-fix-WCCOM-2096-fatal-when-cart-not-initialized
new file mode 100644
index 0000000000..4381fca00f
--- /dev/null
+++ b/plugins/woocommerce/changelog/62644-fix-WCCOM-2096-fatal-when-cart-not-initialized
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Add null-check to cart handler--prevents accessing cart if not initialized
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/class-wc-form-handler.php b/plugins/woocommerce/includes/class-wc-form-handler.php
index 28639672e9..f1d9864e85 100644
--- a/plugins/woocommerce/includes/class-wc-form-handler.php
+++ b/plugins/woocommerce/includes/class-wc-form-handler.php
@@ -868,6 +868,11 @@ class WC_Form_Handler {
 	 * @return bool success or not
 	 */
 	private static function add_to_cart_handler_simple( $product_id ) {
+		if ( ! WC()->cart ) {
+			wc_doing_it_wrong( __FUNCTION__, 'Cart is not initialized.', '10.5.0' );
+			return false;
+		}
+
 		$quantity          = empty( $_REQUEST['quantity'] ) ? 1 : wc_stock_amount( wp_unslash( $_REQUEST['quantity'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
 		$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );