-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Fix/37599 Add Product Name in the aria-label attribute
#37830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
QA Update ✅The aria label should have 'Remove XX'; where XX is the product name. Earlier it was 'Remove this item'. Testing Environment
QA Status- Pass ✅ |
| '<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>', | ||
| esc_url( wc_get_cart_remove_url( $cart_item_key ) ), | ||
| esc_html__( 'Remove this item', 'woocommerce' ), | ||
| sprintf( esc_attr__( 'Remove %s', 'woocommerce' ), $product_name ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR, @faisal-alvi! I didn't do a full review, but leaving a question here (maybe for @opr?):
The Cart block uses Remove %s from cart. I don't have a strong preference between both strings, but it might be a good idea to unify them, so we reduce the work for translators. Reusing the existing one in the Cart block would also guarantee that we have available translations. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great idea, Remove %s from cart sounds good!
opr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @faisal-alvi, thanks for working on this! I tested this and it works really, well, however I have requested some changes which you can see in-line.
I would also like to request changes to your testing notes in the main PR body.
Please could you add some steps to describe testing the mini cart, and could you also add some steps to describe testing this with a screen reader?
Thanks!
| '<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>', | ||
| esc_url( wc_get_cart_remove_url( $cart_item_key ) ), | ||
| esc_html__( 'Remove this item', 'woocommerce' ), | ||
| sprintf( esc_attr__( 'Remove %s', 'woocommerce' ), $product_name ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a translation hint above, to note that %s is the product name.
Like so: /* translators: %s is the product name */
| '<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>', | ||
| esc_url( wc_get_cart_remove_url( $cart_item_key ) ), | ||
| esc_html__( 'Remove this item', 'woocommerce' ), | ||
| sprintf( esc_attr__( 'Remove %s', 'woocommerce' ), $product_name ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this line, only the translated string "Remove %s" is escaped. Not the product name. The product name is filled in after the escape.
I think we should do it like this, to ensure the product name is escaped correctly, too:
| sprintf( esc_attr__( 'Remove %s', 'woocommerce' ), $product_name ), | |
| esc_attr( sprintf( __( 'Remove %s', 'woocommerce' ), $product_name ) ), | |
| '<a href="%s" class="remove remove_from_cart_button" aria-label="%s" data-product_id="%s" data-cart_item_key="%s" data-product_sku="%s">×</a>', | ||
| esc_url( wc_get_cart_remove_url( $cart_item_key ) ), | ||
| esc_attr__( 'Remove this item', 'woocommerce' ), | ||
| sprintf( esc_attr__( 'Remove %s', 'woocommerce' ), $product_name ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the suggestion above, we should do esc_attr on the final result.
| sprintf( esc_attr__( 'Remove %s', 'woocommerce' ), $product_name ), | |
| esc_attr( sprintf( __( 'Remove %s', 'woocommerce' ), $product_name ) ), | |
We also need a /* translators: comment above this use of __
Co-authored-by: Thomas Roberts <[email protected]>
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## trunk #37830 +/- ##
==========================================
- Coverage 51.5% 51.5% -0.0%
- Complexity 17261 17292 +31
==========================================
Files 429 430 +1
Lines 79957 80078 +121
==========================================
+ Hits 41215 41239 +24
- Misses 38742 38839 +97
|
|
@opr thanks for the feedback. The suggestions/changes are implemented. I've also added steps to describe testing the mini cart, and steps to describe testing this with a screen reader in the PR description: #37830 (comment). |
rrennick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@faisal-alvi Thanks for submitting this. In addition to my comment below, the template version in both templates needs to be updated to 7.8.0.
| $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); | ||
| $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); | ||
| $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); | ||
| $product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some $_product->get_name() calls further down in the template that should be updated to $product_name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, those are replaced too. Thanks 70cbbee
|
@rrennick Thanks for the feedback. The requested changes are implemented. Please check. |
rrennick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@faisal-alvi Looks great. Thanks for participating in the contributor day.
opr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks for your contribution @faisal-alvi!
|
Hi, Try this code for example, where the data comes from custom fields. |
…8999) * Send $product_name through woocommerce_cart_item_name filter only once. Closes #38744. * Replace additional product name filters, with already filtered variable. * add additional params to docblock of woocommerce_cart_item_name * bump template version to 7.9.0 * revert cart_item_name filter change in #37830 * Minor fixes * Bump template version --------- Co-authored-by: Ron Rennick <[email protected]> Co-authored-by: Jorge A. Torres <[email protected]>
…8999) * Send $product_name through woocommerce_cart_item_name filter only once. Closes #38744. * Replace additional product name filters, with already filtered variable. * add additional params to docblock of woocommerce_cart_item_name * bump template version to 7.9.0 * revert cart_item_name filter change in #37830 * Minor fixes * Bump template version --------- Co-authored-by: Ron Rennick <[email protected]> Co-authored-by: Jorge A. Torres <[email protected]>
* Send $product_name through woocommerce_cart_item_name filter once (#38999) * Send $product_name through woocommerce_cart_item_name filter only once. Closes #38744. * Replace additional product name filters, with already filtered variable. * add additional params to docblock of woocommerce_cart_item_name * bump template version to 7.9.0 * revert cart_item_name filter change in #37830 * Minor fixes * Bump template version --------- Co-authored-by: Ron Rennick <[email protected]> Co-authored-by: Jorge A. Torres <[email protected]> * Prep for cherry pick 38999 --------- Co-authored-by: Kathy <[email protected]> Co-authored-by: Ron Rennick <[email protected]> Co-authored-by: Jorge A. Torres <[email protected]> Co-authored-by: WooCommerce Bot <[email protected]>


Submission Review Guidelines:
Changes proposed in this Pull Request:
Adds a Product Name in the
aria-labelattribute on the cart page.Closes #37599.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions: