diff --git a/plugins/woocommerce/changelog/51668-fix-51404-action-aria-labels b/plugins/woocommerce/changelog/51668-fix-51404-action-aria-labels
new file mode 100644
index 00000000000..164fab28199
--- /dev/null
+++ b/plugins/woocommerce/changelog/51668-fix-51404-action-aria-labels
@@ -0,0 +1,4 @@
+Significance: minor
+Type: fix
+
+Ensure the order action aria-labels are different for each action.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/wc-account-functions.php b/plugins/woocommerce/includes/wc-account-functions.php
index 7a4fe452588..0f6c02a68f9 100644
--- a/plugins/woocommerce/includes/wc-account-functions.php
+++ b/plugins/woocommerce/includes/wc-account-functions.php
@@ -298,16 +298,22 @@ function wc_get_account_orders_actions( $order ) {
$actions = array(
'pay' => array(
- 'url' => $order->get_checkout_payment_url(),
- 'name' => __( 'Pay', 'woocommerce' ),
+ 'url' => $order->get_checkout_payment_url(),
+ 'name' => __( 'Pay', 'woocommerce' ),
+ /* translators: %s: order number */
+ 'aria-label' => sprintf( __( 'Pay for order %s', 'woocommerce' ), $order->get_order_number() ),
),
'view' => array(
- 'url' => $order->get_view_order_url(),
- 'name' => __( 'View', 'woocommerce' ),
+ 'url' => $order->get_view_order_url(),
+ 'name' => __( 'View', 'woocommerce' ),
+ /* translators: %s: order number */
+ 'aria-label' => sprintf( __( 'View order %s', 'woocommerce' ), $order->get_order_number() ),
),
'cancel' => array(
- 'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
- 'name' => __( 'Cancel', 'woocommerce' ),
+ 'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
+ 'name' => __( 'Cancel', 'woocommerce' ),
+ /* translators: %s: order number */
+ 'aria-label' => sprintf( __( 'Cancel order %s', 'woocommerce' ), $order->get_order_number() ),
),
);
diff --git a/plugins/woocommerce/templates/myaccount/orders.php b/plugins/woocommerce/templates/myaccount/orders.php
index 447c81f2224..5a54c6561d7 100644
--- a/plugins/woocommerce/templates/myaccount/orders.php
+++ b/plugins/woocommerce/templates/myaccount/orders.php
@@ -14,7 +14,7 @@
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
- * @version 9.2.0
+ * @version 9.5.0
*/
defined( 'ABSPATH' ) || exit;
@@ -75,8 +75,15 @@ do_action( 'woocommerce_before_account_orders', $has_orders ); ?>
if ( ! empty( $actions ) ) {
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
- /* translators: %s: order number */
- echo '' . esc_html( $action['name'] ) . '';
+ if ( empty( $action['aria-label'] ) ) {
+ // Generate the aria-label based on the action name.
+ /* translators: %1$s Action name, %2$s Order number. */
+ $action_aria_label = sprintf( __( '%1$s order number %2$s', 'woocommerce' ), $action['name'], $order->get_order_number() );
+ } else {
+ $action_aria_label = $action['aria-label'];
+ }
+ echo '' . esc_html( $action['name'] ) . '';
+ unset( $action_aria_label );
}
}
?>
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/account/functions.php b/plugins/woocommerce/tests/legacy/unit-tests/account/functions.php
index db1a701439f..61e12101159 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/account/functions.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/account/functions.php
@@ -175,21 +175,25 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
* @since 3.3.0
*/
public function test_wc_get_account_orders_actions() {
- $order = WC_Helper_Order::create_order();
+ $order = WC_Helper_Order::create_order();
+ $order_id = $order->get_id();
$this->assertEquals(
array(
'view' => array(
- 'url' => $order->get_view_order_url(),
- 'name' => 'View',
+ 'url' => $order->get_view_order_url(),
+ 'name' => 'View',
+ 'aria-label' => "View order {$order_id}",
),
'pay' => array(
- 'url' => $order->get_checkout_payment_url(),
- 'name' => 'Pay',
+ 'url' => $order->get_checkout_payment_url(),
+ 'name' => 'Pay',
+ 'aria-label' => "Pay for order {$order_id}",
),
'cancel' => array(
- 'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
- 'name' => 'Cancel',
+ 'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
+ 'name' => 'Cancel',
+ 'aria-label' => "Cancel order {$order_id}",
),
),
wc_get_account_orders_actions( $order->get_id() )