Add ability to select dar versions of Visa and Mastercard icons.

This commit is contained in:
Narek Zakarian 2022-04-04 17:01:14 +04:00
parent d6286ec6e5
commit b78da2daae
3 changed files with 54 additions and 10 deletions

View file

@ -1959,13 +1959,15 @@ return array(
'woocommerce-paypal-payments'
),
'options' => array(
'visa' => _x( 'Visa', 'Name of credit card', 'woocommerce-paypal-payments' ),
'mastercard' => _x( 'Mastercard', 'Name of credit card', 'woocommerce-paypal-payments' ),
'amex' => _x( 'American Express', 'Name of credit card', 'woocommerce-paypal-payments' ),
'discover' => _x( 'Discover', 'Name of credit card', 'woocommerce-paypal-payments' ),
'jcb' => _x( 'JCB', 'Name of credit card', 'woocommerce-paypal-payments' ),
'elo' => _x( 'Elo', 'Name of credit card', 'woocommerce-paypal-payments' ),
'hiper' => _x( 'Hiper', 'Name of credit card', 'woocommerce-paypal-payments' ),
'visa' => _x( 'Visa (light)', 'Name of credit card', 'woocommerce-paypal-payments' ),
'visa-dark' => _x( 'Visa (dark)', 'Name of credit card', 'woocommerce-paypal-payments' ),
'mastercard' => _x( 'Mastercard (light)', 'Name of credit card', 'woocommerce-paypal-payments' ),
'mastercard-dark' => _x( 'Mastercard (dark)', 'Name of credit card', 'woocommerce-paypal-payments' ),
'amex' => _x( 'American Express', 'Name of credit card', 'woocommerce-paypal-payments' ),
'discover' => _x( 'Discover', 'Name of credit card', 'woocommerce-paypal-payments' ),
'jcb' => _x( 'JCB', 'Name of credit card', 'woocommerce-paypal-payments' ),
'elo' => _x( 'Elo', 'Name of credit card', 'woocommerce-paypal-payments' ),
'hiper' => _x( 'Hiper', 'Name of credit card', 'woocommerce-paypal-payments' ),
),
'screens' => array(
State::STATE_ONBOARDED,
@ -2041,14 +2043,23 @@ return array(
* Here, we filter them out.
*/
$card_options = $fields['disable_cards']['options'];
$card_icons = $fields['card_icons']['options'];
$dark_versions = array();
foreach ( $card_options as $card => $label ) {
if ( $dcc_applies->can_process_card( $card ) ) {
if ( 'visa' === $card || 'mastercard' === $card ) {
$dark_versions = array(
'visa-dark' => $card_icons['visa-dark'],
'mastercard-dark' => $card_icons['mastercard-dark'],
);
}
continue;
}
unset( $card_options[ $card ] );
}
$fields['disable_cards']['options'] = $card_options;
$fields['card_icons']['options'] = $card_options;
$fields['card_icons']['options'] = array_merge( $dark_versions, $card_options );
/**
* Display vault message on Pay Later label if vault is enabled.

View file

@ -331,8 +331,9 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
$title_options = $this->card_labels();
$images = array_map(
function ( string $type ) use ( $title_options ): string {
$striped_dark = str_replace( '-dark', '', $type );
return '<img
title="' . esc_attr( $title_options[ $type ] ) . '"
title="' . esc_attr( $title_options[ $striped_dark ] ) . '"
src="' . esc_url( $this->module_url ) . 'assets/images/' . esc_attr( $type ) . '.svg"
class="ppcp-card-icon"
> ';