The Stripe extension payment form has placeholder values that are automatically translated by Stripe. By default, they use the visitor’s browser locale.
These placeholders cannot be translated via the usual methods because the form is loaded in an iframe
, so we’ve shown how to translate them below.
If you are using the legacy checkout experience, you can change the language with the wc_stripe_elements_options
filter. For example, to change the placeholder text to use the site locale, you can use this snippet:
function wc_update_locale_in_stripe_element_options( $options ) {
return array_merge(
$options,
array(
'locale' => get_locale(),
)
);
};
add_filter( 'wc_stripe_elements_options', 'wc_update_locale_in_stripe_element_options' );
Alternatively, you can replace the get_locale()
string with your preferred locale value. Here’s a similar snippet that will force the placeholder text in the Stripe card fields to be localized into Italian:
function wc_update_locale_in_stripe_element_options( $options ) {
return array_merge(
$options,
array(
'locale' => 'it',
)
);
};
add_filter( 'wc_stripe_elements_options', 'wc_update_locale_in_stripe_element_options' );
This Stripe document shows which locales they support.
NOTE: We are unable to provide support for custom code under our Support Policy. If you need to customize a snippet further or extend its functionality, we highly recommend Codeable or a Certified WooExpert.