Commit a313c80ca5 for woocommerce
commit a313c80ca5bdc1e869757a4de7d5a67395f61e0a
Author: Albert Juhé Lluveras <contact@albertjuhe.com>
Date: Thu Feb 12 11:08:40 2026 +0100
Don't disable variable products add to cart button in any case (#63260)
* Don't disable variable products add to cart button in any case
* Add changelog file
* Update template version
* Update template version
* Remove tests
diff --git a/plugins/woocommerce/changelog/fix-undo-changes-to-disable-add-to-cart-button b/plugins/woocommerce/changelog/fix-undo-changes-to-disable-add-to-cart-button
new file mode 100644
index 0000000000..6ff67bfb0d
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-undo-changes-to-disable-add-to-cart-button
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix variable products add-to-cart button appearing disabled in some stores
diff --git a/plugins/woocommerce/client/legacy/js/frontend/add-to-cart-variation.js b/plugins/woocommerce/client/legacy/js/frontend/add-to-cart-variation.js
index 2df4717f71..b4334f7bef 100644
--- a/plugins/woocommerce/client/legacy/js/frontend/add-to-cart-variation.js
+++ b/plugins/woocommerce/client/legacy/js/frontend/add-to-cart-variation.js
@@ -103,13 +103,6 @@
setTimeout( function () {
$form.trigger( 'check_variations' );
$form.trigger( 'wc_variation_form', self );
-
- // For variable products, we disable the button by default to avoid
- // shoppers submitting the form with invalid data. We remove the
- // disabled attribute as soon as the script is loaded and let the
- // script handle the button state.
- // @see https://github.com/woocommerce/woocommerce/issues/62448
- $form.find( '.single_add_to_cart_button' ).removeAttr( 'disabled' );
self.loading = false;
}, 100 );
};
diff --git a/plugins/woocommerce/templates/single-product/add-to-cart/variation-add-to-cart-button.php b/plugins/woocommerce/templates/single-product/add-to-cart/variation-add-to-cart-button.php
index c6f115576a..81960d75c5 100644
--- a/plugins/woocommerce/templates/single-product/add-to-cart/variation-add-to-cart-button.php
+++ b/plugins/woocommerce/templates/single-product/add-to-cart/variation-add-to-cart-button.php
@@ -4,20 +4,12 @@
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
- * @version 10.5.1
+ * @version 10.5.2
*/
defined( 'ABSPATH' ) || exit;
global $product;
-
-/*
- * By default, the add to cart button is disabled to prevent shoppers from interacting with it
- * while the WooCommerce variation script is still loading. If the default variation script
- * (wc-add-to-cart-variation) is not enqueued, the button remains enabled to ensure compatibility
- * with stores that use this template without the script.
- */
-$is_add_to_cart_button_disabled = wp_script_is( 'wc-add-to-cart-variation', 'enqueued' );
?>
<div class="woocommerce-variation-add-to-cart variations_button">
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
@@ -36,7 +28,7 @@ $is_add_to_cart_button_disabled = wp_script_is( 'wc-add-to-cart-variation', 'enq
do_action( 'woocommerce_after_add_to_cart_quantity' );
?>
- <button type="submit" class="single_add_to_cart_button button alt<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>"<?php echo $is_add_to_cart_button_disabled ? ' disabled' : ''; ?>><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
+ <button type="submit" class="single_add_to_cart_button button alt<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-variation-add-to-cart-button-test.php b/plugins/woocommerce/tests/php/includes/class-wc-variation-add-to-cart-button-test.php
deleted file mode 100644
index f0b446c612..0000000000
--- a/plugins/woocommerce/tests/php/includes/class-wc-variation-add-to-cart-button-test.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-declare( strict_types = 1 );
-
-/**
- * Unit tests for the variation add-to-cart button template and disabled state.
- *
- * @package WooCommerce\Tests\Includes
- */
-
-/**
- * Class WC_Variation_Add_To_Cart_Button_Test
- */
-class WC_Variation_Add_To_Cart_Button_Test extends \WC_Unit_Test_Case {
-
- /**
- * Variable product for template tests.
- *
- * @var WC_Product_Variable
- */
- private $product;
-
- /**
- * Runs before each test.
- */
- public function setUp(): void {
- parent::setUp();
- $this->product = WC_Helper_Product::create_variation_product();
- }
-
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- global $product;
- $product = null;
- wp_dequeue_script( 'wc-add-to-cart-variation' );
- parent::tearDown();
- }
-
- /**
- * Renders the variation add-to-cart button template and returns HTML.
- *
- * @return string
- */
- private function render_template(): string {
- global $product;
- $product = $this->product;
- return wc_get_template_html( 'single-product/add-to-cart/variation-add-to-cart-button.php' );
- }
-
- /**
- * Asserts the rendered button has the disabled attribute.
- *
- * @param string $html Rendered template HTML.
- */
- private function assert_button_is_disabled( string $html ): void {
- $this->assertStringContainsString( 'single_add_to_cart_button', $html );
- $this->assertStringContainsString( ' disabled>', $html, 'Add to cart button should be disabled' );
- }
-
- /**
- * Asserts the rendered button does not have the disabled attribute.
- *
- * @param string $html Rendered template HTML.
- */
- private function assert_button_is_enabled( string $html ): void {
- $this->assertStringContainsString( 'single_add_to_cart_button', $html );
- $this->assertStringNotContainsString( ' disabled>', $html, 'Add to cart button should not be disabled' );
- }
-
- /**
- * Registers and enqueues the wc-add-to-cart-variation script so wp_script_is( 'wc-add-to-cart-variation', 'enqueued' ) is true.
- */
- private function register_and_enqueue_variation_script(): void {
- if ( ! wp_script_is( 'wc-add-to-cart-variation', 'registered' ) ) {
- wp_register_script(
- 'wc-add-to-cart-variation',
- 'https://example.com/wc-add-to-cart-variation.js',
- array( 'jquery' ),
- WC_VERSION,
- true
- );
- }
- wp_enqueue_script( 'wc-add-to-cart-variation' );
- }
-
- /**
- * @testdox When wc-add-to-cart-variation is not enqueued, the button is enabled.
- */
- public function test_when_script_not_enqueued_renders_enabled_button(): void {
- $html = $this->render_template();
- $this->assert_button_is_enabled( $html );
- }
-
- /**
- * @testdox When wc-add-to-cart-variation is enqueued, the button is disabled.
- */
- public function test_when_script_enqueued_renders_disabled_button(): void {
- $this->register_and_enqueue_variation_script();
- $html = $this->render_template();
- $this->assert_button_is_disabled( $html );
- }
-}