diff --git a/modules/ppcp-card-fields/src/CardFieldsModule.php b/modules/ppcp-card-fields/src/CardFieldsModule.php index faa36a3bc..213134857 100644 --- a/modules/ppcp-card-fields/src/CardFieldsModule.php +++ b/modules/ppcp-card-fields/src/CardFieldsModule.php @@ -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, diff --git a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php index f2903d239..a1a3b8f06 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php @@ -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. *