Commit 8d651016b52 for woocommerce

commit 8d651016b524825e092f56c4d1e72f91a9369f90
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Mon Nov 23 15:00:29 2026 +0100

    Enforce customer registration settings in form handlers (#71241)

    (cherry picked from commit 2b8b7574a6d3d1f0873c8c566c854563a17a1fde)

diff --git a/plugins/woocommerce/includes/class-wc-checkout.php b/plugins/woocommerce/includes/class-wc-checkout.php
index e4e071ef12e..94c1d489d4b 100644
--- a/plugins/woocommerce/includes/class-wc-checkout.php
+++ b/plugins/woocommerce/includes/class-wc-checkout.php
@@ -1925,6 +1925,16 @@ class WC_Checkout {
 			// Validate posted data and cart items before proceeding.
 			$this->validate_checkout( $posted_data, $errors );

+			if ( ! is_user_logged_in() && ! $this->is_registration_enabled() && $this->is_registration_required() ) {
+				/**
+				 * This filter is documented in the Store API checkout route.
+				 *
+				 * @since 9.4.3
+				 */
+				$message = apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) );
+				$errors->add( 'registration_disabled', esc_html( is_string( $message ) ? $message : __( 'You must be logged in to checkout.', 'woocommerce' ) ) );
+			}
+
 			if ( empty( $errors->errors ) ) {
 				wc_log_order_step( '[Shortcode #3] Checkout posted data validated', array( 'payment_method' => $posted_data['payment_method'] ) );
 			}
diff --git a/plugins/woocommerce/includes/class-wc-form-handler.php b/plugins/woocommerce/includes/class-wc-form-handler.php
index 6c2c2516514..f478d954edd 100644
--- a/plugins/woocommerce/includes/class-wc-form-handler.php
+++ b/plugins/woocommerce/includes/class-wc-form-handler.php
@@ -1654,6 +1654,11 @@ class WC_Form_Handler {
 		$nonce_value = isset( $_POST['woocommerce-register-nonce'] ) ? wp_unslash( $_POST['woocommerce-register-nonce'] ) : $nonce_value; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

 		if ( isset( $_POST['register'], $_POST['email'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-register' ) ) {
+			if ( 'yes' !== get_option( 'woocommerce_enable_myaccount_registration' ) ) {
+				wc_add_notice( __( 'Registration is disabled.', 'woocommerce' ), 'error' );
+				return;
+			}
+
 			$username = 'no' === get_option( 'woocommerce_registration_generate_username' ) && isset( $_POST['username'] ) ? wp_unslash( $_POST['username'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
 			$password = 'no' === get_option( 'woocommerce_registration_generate_password' ) && isset( $_POST['password'] ) ? $_POST['password'] : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
 			$email    = wp_unslash( $_POST['email'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized