diff --git a/plugins/woocommerce/changelog/48262-patch-16 b/plugins/woocommerce/changelog/48262-patch-16 new file mode 100644 index 00000000000..0bb1bf32a6e --- /dev/null +++ b/plugins/woocommerce/changelog/48262-patch-16 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix the order-items view for coupons, so we show the actually-used coupon info, if it exists. \ 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 f7f40056007..bb2cf596d79 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 @@ -118,8 +118,14 @@ if ( wc_tax_enabled() ) {
  • $item ) : - $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' LIMIT 1;", $item->get_code() ) ); // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited - $class = $order->is_editable() ? 'code editable' : 'code'; + $coupon_info = $item->get_meta( 'coupon_info' ); + if ( $coupon_info ) { + $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;", $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'; ?>