Don't render aria described by if the arg is not passed in add-to-cart.php (#48969)
This commit is contained in:
parent
4ac3ce099c
commit
0a47061ace
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Avoid PHP warnings if `add-to-cart.php` template does not pass `aria-describedby_text`
|
|
@ -12,7 +12,7 @@
|
|||
*
|
||||
* @see https://woocommerce.com/document/template-structure/
|
||||
* @package WooCommerce\Templates
|
||||
* @version 9.0.0
|
||||
* @version 9.2.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -21,12 +21,14 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
global $product;
|
||||
|
||||
$aria_describedby = isset( $args['aria-describedby_text'] ) ? sprintf( 'aria-describedby="woocommerce_loop_add_to_cart_link_describedby_%s"', esc_attr( $product->get_id() ) ) : '';
|
||||
|
||||
echo apply_filters(
|
||||
'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
|
||||
sprintf(
|
||||
'<a href="%s" aria-describedby="woocommerce_loop_add_to_cart_link_describedby_%s" data-quantity="%s" class="%s" %s>%s</a>',
|
||||
'<a href="%s" %s data-quantity="%s" class="%s" %s>%s</a>',
|
||||
esc_url( $product->add_to_cart_url() ),
|
||||
esc_attr( $product->get_id() ),
|
||||
$aria_describedby,
|
||||
esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
|
||||
esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
|
||||
isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
|
||||
|
@ -36,6 +38,8 @@ echo apply_filters(
|
|||
$args
|
||||
);
|
||||
?>
|
||||
<span id="woocommerce_loop_add_to_cart_link_describedby_<?php echo esc_attr( $product->get_id() ); ?>" class="screen-reader-text">
|
||||
<?php echo esc_html( $args['aria-describedby_text'] ); ?>
|
||||
</span>
|
||||
<?php if ( isset( $args['aria-describedby_text'] ) ) : ?>
|
||||
<span id="woocommerce_loop_add_to_cart_link_describedby_<?php echo esc_attr( $product->get_id() ); ?>" class="screen-reader-text">
|
||||
<?php echo esc_html( $args['aria-describedby_text'] ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
|
|
Loading…
Reference in New Issue