Commit e36db9eb24f for woocommerce
commit e36db9eb24f08908eaab5496fb72ae66a987cad0
Author: Marco Almeida | Webdados <webdados@users.noreply.github.com>
Date: Mon Aug 31 13:26:55 2026 +0100
Do not remove the whole order fieldset when order notes are disabled (#68169)
* Do not tie the whole order fieldset to the order notes setting (#68168)
form-shipping.php wrapped the entire order fieldset in the
woocommerce_enable_order_notes_field check, so disabling order notes removed
every other field registered in that fieldset as well, not just
order_comments. Those fields are still collected by get_posted_data() and
still checked by validate_posted_data(), and maybe_skip_fieldset() only ever
skips shipping and account, so a required field there blocked checkout with
an error naming a field that was not on the page.
The setting now scopes to the field it is named after, and the fieldset
renders whenever it has something to render.
The heading moves with it. It was inside a second condition, so on a cart
that needs shipping there was no heading at all and the fields followed
div.woocommerce-shipping-fields directly, reading as part of "Ship to a
different address?". The order notes textarea carries its own label and gets
away with that; a "Purchase order number" added by an extension does not.
Nothing stops rendering and no field moves in the DOM. On a store with no
added fields and order notes off, the fieldset is empty and nothing is
output, as before. The one visible change is that a store with a shippable
cart now gets the same "Additional information" heading it already shows on a
virtual cart.
@version bumped so an outdated theme override is flagged in Status.
* Update plugins/woocommerce/templates/checkout/form-shipping.php
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
* Move the order notes setting out of the checkout template
Add order_comments in WC_Checkout::initialize_checkout_fields() only when
woocommerce_enable_order_notes_field passes, instead of adding it always and
unsetting it in form-shipping.php. Extensions and theme overrides no longer
have to repeat the check.
The field is now absent from get_checkout_fields() when the setting is off, so
a posted order_comments is no longer saved to the customer note.
---------
Co-authored-by: Marco Almeida <marcoalmeida@webdados.pt>
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
diff --git a/plugins/woocommerce/changelog/68168-order-fieldset-not-tied-to-order-notes b/plugins/woocommerce/changelog/68168-order-fieldset-not-tied-to-order-notes
new file mode 100644
index 00000000000..371b91da0cb
--- /dev/null
+++ b/plugins/woocommerce/changelog/68168-order-fieldset-not-tied-to-order-notes
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix the shortcode checkout dropping every other field in the order fieldset when order notes are disabled, which also left a required field there blocking checkout with no way to fill it in.
diff --git a/plugins/woocommerce/includes/class-wc-checkout.php b/plugins/woocommerce/includes/class-wc-checkout.php
index d7b60a72047..142a1c32ee2 100644
--- a/plugins/woocommerce/includes/class-wc-checkout.php
+++ b/plugins/woocommerce/includes/class-wc-checkout.php
@@ -268,19 +268,28 @@ class WC_Checkout {
'shipping_'
),
'account' => array(),
- 'order' => array(
- 'order_comments' => array(
- 'type' => 'textarea',
- 'class' => array( 'notes' ),
- 'label' => __( 'Order notes', 'woocommerce' ),
- 'placeholder' => esc_attr__(
- 'Notes about your order, e.g. special notes for delivery.',
- 'woocommerce'
- ),
- ),
- ),
+ 'order' => array(),
);
+ /**
+ * Controls whether the order notes field is added to the checkout.
+ *
+ * @since 2.1.0
+ *
+ * @param bool $enabled Whether the order notes field is enabled.
+ */
+ if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) {
+ $this->fields['order']['order_comments'] = array(
+ 'type' => 'textarea',
+ 'class' => array( 'notes' ),
+ 'label' => __( 'Order notes', 'woocommerce' ),
+ 'placeholder' => esc_attr__(
+ 'Notes about your order, e.g. special notes for delivery.',
+ 'woocommerce'
+ ),
+ );
+ }
+
if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) {
$this->fields['account']['account_username'] = array(
'type' => 'text',
diff --git a/plugins/woocommerce/templates/checkout/form-shipping.php b/plugins/woocommerce/templates/checkout/form-shipping.php
index 727f9deb035..b92f610ce7f 100644
--- a/plugins/woocommerce/templates/checkout/form-shipping.php
+++ b/plugins/woocommerce/templates/checkout/form-shipping.php
@@ -12,7 +12,7 @@
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
- * @version 3.6.0
+ * @version 11.2.0
* @global WC_Checkout $checkout
*/
@@ -50,16 +50,14 @@ defined( 'ABSPATH' ) || exit;
<div class="woocommerce-additional-fields">
<?php do_action( 'woocommerce_before_order_notes', $checkout ); ?>
- <?php if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) : ?>
+ <?php $order_fields = $checkout->get_checkout_fields( 'order' ); ?>
- <?php if ( ! WC()->cart->needs_shipping() || wc_ship_to_billing_address_only() ) : ?>
+ <?php if ( ! empty( $order_fields ) ) : ?>
- <h3><?php esc_html_e( 'Additional information', 'woocommerce' ); ?></h3>
-
- <?php endif; ?>
+ <h3><?php esc_html_e( 'Additional information', 'woocommerce' ); ?></h3>
<div class="woocommerce-additional-fields__field-wrapper">
- <?php foreach ( $checkout->get_checkout_fields( 'order' ) as $key => $field ) : ?>
+ <?php foreach ( $order_fields as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
</div>