Remove the str_replace CVC placeholder adjusting in favor of using the existing translation

This commit is contained in:
Daniel Dudzic 2024-03-11 18:18:06 +01:00
parent f3da7a3162
commit fd4a21a356
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
2 changed files with 19 additions and 11 deletions

View file

@ -97,17 +97,6 @@ class CardFieldsModule implements ModuleInterface {
}
}
if ( apply_filters( 'woocommerce_paypal_payments_card_fields_translate_card_cvv', true ) ) {
if ( isset( $default_fields['card-cvc-field'] ) ) {
// Replaces the default card cvc placeholder with a translatable one (which also matches the CVV field label).
$default_fields['card-cvc-field'] = str_replace(
'CVC',
esc_attr__( 'CVV', 'woocommerce-paypal-payments' ),
$default_fields['card-cvc-field']
);
}
}
return $default_fields;
},
10,

View file

@ -291,8 +291,10 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
*/
public function form() {
add_action( 'gettext', array( $this, 'replace_credit_card_cvv_label' ), 10, 3 );
add_action( 'gettext', array( $this, 'replace_credit_card_cvv_placeholder' ), 10, 3 );
parent::form();
remove_action( 'gettext', 'replace_credit_card_cvv_label' );
remove_action( 'gettext', 'replace_credit_card_cvv_placeholder' );
}
/**
@ -312,6 +314,23 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
return __( 'CVV', 'woocommerce-paypal-payments' );
}
/**
* Replace WooCommerce credit card CVV field placeholder.
*
* @param string $translation Translated text.
* @param string $text Original text to translate.
* @param string $domain Text domain.
*
* @return string Translated field.
*/
public function replace_credit_card_cvv_placeholder( string $translation, string $text, string $domain ): string {
if ( 'woocommerce' !== $domain || 'CVC' !== $text || ! apply_filters( 'woocommerce_paypal_payments_card_fields_translate_card_cvv', true ) ) {
return $translation;
}
return __( 'CVV', 'woocommerce-paypal-payments' );
}
/**
* Returns the icons of the gateway.
*