Skip to content

Conversation

@faisal-alvi
Copy link
Contributor

@faisal-alvi faisal-alvi commented Apr 19, 2023

Submission Review Guidelines:

Changes proposed in this Pull Request:

Adds a Product Name in the aria-label attribute 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:

  1. Use the storefront theme (this is to see the mini cart popup in the header).
  2. Add a product to the cart.
  3. Visit the cart page.
  4. Activate the screen reader on your device. For Windows users, you can use NVDA or JAWS screen reader. For Mac users, you can use VoiceOver.
  5. Once the screen reader is activated, navigate to the 'X' icon beside the product in the cart. Use the screen reader's keyboard commands to reach it. For example, use the "Tab" key to move between links, buttons, and form fields.
  6. It should say "Remove XX from cart". Where XX is the product name.

image

  1. Now visit the shop page, and check the top right side cart icon, hover over it and navigate to the 'X' icon in the popup.
  2. Again, it should say "Remove XX from cart". Where XX is the product name.

image

@github-actions github-actions bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution labels Apr 19, 2023
@woocommercebot woocommercebot requested review from a team and rrennick and removed request for a team April 19, 2023 10:56
@qasumitbagthariya
Copy link
Collaborator

QA Update ✅


The aria label should have 'Remove XX'; where XX is the product name. Earlier it was 'Remove this item'.

Testing Environment

  • WordPress: 6.2
  • Theme: Storefront 4.2.0
  • Woocommerce - 7.6.0
  • PHP: 8.0.21
  • Web Server: Nginx 1.20.2
  • Browser: Chrome
  • OS: Windows 11
  • Git Branch: faisal-alvi:fix/37599

image
image

QA Status- Pass ✅

'<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">&times;</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 ),
Copy link
Contributor

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?

Copy link
Contributor

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!

Copy link
Contributor

@opr opr left a 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">&times;</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 ),
Copy link
Contributor

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">&times;</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 ),
Copy link
Contributor

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:

Suggested change
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">&times;</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 ),
Copy link
Contributor

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.

Suggested change
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 __

@codecov
Copy link

codecov bot commented Apr 19, 2023

Codecov Report

Merging #37830 (e524e95) into trunk (e8fcfbb) will decrease coverage by 0.0%.
The diff coverage is 0.0%.

❗ Current head e524e95 differs from pull request most recent head 78fce9a. Consider uploading reports for the commit 78fce9a to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
...ocommerce/includes/admin/class-wc-admin-assets.php 0.0% <ø> (ø)
...eta-boxes/class-wc-meta-box-product-categories.php 0.0% <0.0%> (ø)
plugins/woocommerce/includes/class-wc-ajax.php 4.3% <0.0%> (-0.1%) ⬇️

... and 11 files with indirect coverage changes

@faisal-alvi
Copy link
Contributor Author

faisal-alvi commented Apr 20, 2023

@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).

@faisal-alvi faisal-alvi requested a review from opr April 20, 2023 09:04
Copy link
Contributor

@rrennick rrennick left a 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 );
Copy link
Contributor

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.

Copy link
Contributor Author

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

@faisal-alvi
Copy link
Contributor Author

@rrennick Thanks for the feedback. The requested changes are implemented. Please check.

@faisal-alvi faisal-alvi requested a review from rrennick April 21, 2023 08:36
rrennick
rrennick previously approved these changes Apr 21, 2023
Copy link
Contributor

@rrennick rrennick left a 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.

Copy link
Contributor

@opr opr left a 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!

@rrennick rrennick merged commit 2460532 into woocommerce:trunk May 11, 2023
@github-actions github-actions bot added this to the 7.8.0 milestone May 11, 2023
@SiKth
Copy link

SiKth commented Jun 18, 2023

Hi,
This update might have caused and issue with the hook "woocommerce_cart_item_name". A lot of people use this to add information after the product name in the Cart and in the Checkout. Now all that data also gets output in the aria-label field. I have this on my site and when I search for this a lot of people recommend this solution to do just this. Anything we can look into?

Try this code for example, where the data comes from custom fields.

`add_filter( 'woocommerce_cart_item_name', 'cfwc_cart_item_name', 10, 3 );
function cfwc_cart_item_name( $name, $cart_item, $cart_item_key ) {
	
	if( isset( $cart_item['size'] ) ) {
		$name .= '<br><b>Size:</b> ' . $cart_item['size'] . '';
	}
	if( isset( $cart_item['color'] ) ) {
		$name .= '<br><b>Color:</b> ' . $cart_item['color'] . '';
	}
	
	return $name;
}`

rrennick pushed a commit to helgatheviking/woocommerce that referenced this pull request Jun 30, 2023
psealock pushed a commit that referenced this pull request Jul 4, 2023
…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]>
github-actions bot pushed a commit that referenced this pull request Jul 4, 2023
…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]>
psealock pushed a commit that referenced this pull request Jul 4, 2023
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessibility Improvements ‣ Cart ‣ Remove Item 'X' Buttons

7 participants