Skip to content

Commit

Permalink
suggestions implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
faisal-alvi committed May 11, 2023
1 parent b4649e4 commit 99b5c7e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
18 changes: 10 additions & 8 deletions plugins/woocommerce/includes/abstracts/abstract-wc-product.php
Expand Up @@ -1937,14 +1937,16 @@ public function single_add_to_cart_text() {
*
* @return string
*/
public function aria_describedby_description() {
$aria_describedby_description = '';

if ( 'Select options' === $this->add_to_cart_text() ) {
$aria_describedby_description = __( 'This product has multiple variants. The options may be chosen on the product page', 'woocommerce' );
}

return apply_filters( 'woocommerce_product_aria_describedby_description', $aria_describedby_description, $this );
public function add_to_cart_aria_describedby() {
/**
* Filter the aria-describedby description for the add to cart button.
*
* @since x.x.x
*
* @param string $var aria-describedby description.
* @param WC_Product $this object.
*/
return apply_filters( 'woocommerce_product_add_to_cart_aria_describedby', '', $this );
}

/**
Expand Down
9 changes: 9 additions & 0 deletions plugins/woocommerce/includes/class-wc-product-variable.php
Expand Up @@ -51,6 +51,15 @@ public function get_type() {
|--------------------------------------------------------------------------
*/

/**
* Get the aria-describedby description for the add to cart button.
*
* @return string
*/
public function add_to_cart_aria_describedby() {
return apply_filters( 'woocommerce_product_add_to_cart_aria_describedby', $this->is_purchasable() ? __( 'This product has multiple variants. The options may be chosen on the product page', 'woocommerce' ) : '', $this );
}

/**
* Get the add to cart button text.
*
Expand Down
6 changes: 2 additions & 4 deletions plugins/woocommerce/includes/wc-template-functions.php
Expand Up @@ -1365,17 +1365,15 @@ function woocommerce_template_loop_add_to_cart( $args = array() ) {
'data-product_id' => $product->get_id(),
'data-product_sku' => $product->get_sku(),
'aria-label' => $product->add_to_cart_description(),
'aria-describedby' => $product->aria_describedby_description(),
'aria-describedby' => $product->add_to_cart_aria_describedby(),
'rel' => 'nofollow',
),
);

$args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );

if ( isset( $args['attributes']['aria-describedby'] ) && ! empty( $args['attributes']['aria-describedby'] ) ) {
if ( ! empty( $args['attributes']['aria-describedby'] ) ) {
$args['attributes']['aria-describedby'] = wp_strip_all_tags( $args['attributes']['aria-describedby'] );
} else {
unset( $args['attributes']['aria-describedby'] );
}

if ( isset( $args['attributes']['aria-label'] ) ) {
Expand Down

0 comments on commit 99b5c7e

Please sign in to comment.