Commit b84a8383a9d for woocommerce

commit b84a8383a9d398f1f37d3149011d45d4db84385b
Author: Pavel Dohnal <pavel.dohnal@automattic.com>
Date:   Tue Mar 24 11:14:38 2026 +0100

    Restore LOWER() in coupon SQL lookups for case-sensitive collations (#63800)

    * Restore LOWER() in coupon data store query for case-sensitive collations

    Commit 1c4581fba7b4 removed LOWER() from the SQL lookup in
    get_ids_by_code(), relying on the database collation being
    case-insensitive. On case-sensitive collations (e.g. utf8mb4_bin),
    this causes coupon lookups to fail when the input casing doesn't
    match the stored post_title.

    * Restore LOWER() in order items admin coupon lookup query

    Same regression as the data store — the admin order items template
    also had LOWER() removed in 1c4581fba7b4, breaking coupon display
    on case-sensitive collations.

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

    ---------

    Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>

diff --git a/plugins/woocommerce/changelog/63800-fix-WOO6-55-case-sensitive-coupon-lookups b/plugins/woocommerce/changelog/63800-fix-WOO6-55-case-sensitive-coupon-lookups
new file mode 100644
index 00000000000..2807ad92cbc
--- /dev/null
+++ b/plugins/woocommerce/changelog/63800-fix-WOO6-55-case-sensitive-coupon-lookups
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Restore case-insensitive coupon lookups on databases with case-sensitive collations.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/admin/meta-boxes/views/html-order-items.php b/plugins/woocommerce/includes/admin/meta-boxes/views/html-order-items.php
index 6787f8f51ca..a5433567036 100644
--- a/plugins/woocommerce/includes/admin/meta-boxes/views/html-order-items.php
+++ b/plugins/woocommerce/includes/admin/meta-boxes/views/html-order-items.php
@@ -130,7 +130,7 @@ if ( wc_tax_enabled() ) {
 						$coupon_info = json_decode( $coupon_info, true );
 						$post_id     = $coupon_info[0]; //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
 					} else {
-						$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' AND post_date < %s LIMIT 1;", wc_sanitize_coupon_code( $item->get_code() ), $order->get_date_created()->format( 'Y-m-d H:i:s' ) ) ); // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
+						$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE LOWER(post_title) = LOWER(%s) AND post_type = 'shop_coupon' AND post_status = 'publish' AND post_date < %s LIMIT 1;", wc_sanitize_coupon_code( $item->get_code() ), $order->get_date_created()->format( 'Y-m-d H:i:s' ) ) ); // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
 					}
 					$class = $order->is_editable() ? 'code editable' : 'code';
 					?>
diff --git a/plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php b/plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php
index 6b92fb7c0a5..e8e3a41d6a6 100644
--- a/plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php
+++ b/plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php
@@ -789,7 +789,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
 		global $wpdb;
 		return $wpdb->get_col(
 			$wpdb->prepare(
-				"SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' ORDER BY post_date DESC",
+				"SELECT ID FROM $wpdb->posts WHERE LOWER(post_title) = LOWER(%s) AND post_type = 'shop_coupon' AND post_status = 'publish' ORDER BY post_date DESC",
 				wc_sanitize_coupon_code( $code )
 			)
 		);