Skip to content

Commit

Permalink
fix: payment method icon alt text (#9648)
Browse files Browse the repository at this point in the history
Co-authored-by: Brett Shumaker <[email protected]>
  • Loading branch information
frosso and brettshumaker authored Nov 4, 2024
1 parent 68e4986 commit e42103b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-payment-method-icon-alt-text
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

fix: payment method icon alt text
14 changes: 10 additions & 4 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -3231,12 +3231,18 @@ public function update_fraud_rules_based_on_general_options() {
}

/**
* The get_icon() method from the WC_Payment_Gateway class wraps the icon URL into a prepared HTML element, but there are situations when this
* element needs to be rendered differently on the UI (e.g. additional styles or `display` property).
* Overriding the base method because the `alt` tag would otherwise output the markup returned by the `get_title()` method in this class - which we don't want.
*
* This is why we need a usual getter like this to provide a raw icon URL to the UI, which will render it according to particular requirements.
* @return string
*/
public function get_icon() {
return '<img src="' . esc_url( WC_HTTPS::force_https_url( $this->get_icon_url() ) ) . '" alt="' . esc_attr( $this->payment_method->get_title() ) . ' payment method logo" />';
}

/**
* The URL for the current payment method's icon.
*
* @return string Returns the payment method icon URL.
* @return string The payment method icon URL.
*/
public function get_icon_url() {
return $this->payment_method->get_icon();
Expand Down

0 comments on commit e42103b

Please sign in to comment.