The payment fields generated by WooPayments on the checkout page are hosted on a separate PCI-compliant server. As a result, trying to style these elements via custom CSS will not work as expected.
If you would like to modify the styling of the payment fields generated by WooPayments, you will need:
- WooPayments version 7.3.0 or later, and…
- Some custom PHP code, added via either:
- Your theme’s
functions.php
file, or… - A plugin like Code Snippets.
- Your theme’s
NOTE: We are unable to provide support for customizations under our Support Policy. If you need to customize a snippet or extend its functionality, seek assistance from a qualified WooCommerce Developer. We highly recommend Codeable or a Certified WooExpert.
A simple example
↑ Back to topThe following example snippet changes the rounding applied to the form fields.
add_filter( 'wcpay_upe_appearance', function ( $appearance ) {
$appearance->variables->{'borderRadius'} = '20px';
return $appearance;
} );
Here’s a before and after image of the result:
Commonly used variables
↑ Back to topThe table below shows the most commonly used variables.
Variable | Description |
---|---|
borderRadius | The border radius used for tabs, inputs, and other components. |
colorBackground | The color used for the background of inputs, tabs, and other components. |
colorDanger | A color used to indicate errors or destructive actions. |
colorPrimary | The main color used throughout form, usually your primary brand color. |
colorText | The default text color. |
fontFamily | The font family used throughout. |
fontSizeBase | The main font size for all components. |
spacingUnit | The base spacing unit that all other spacing is derived from. Increase or decrease this value to make your layout more or less spacious. |
There are a number of other, less common variables listed in Stripe’s documentation.
Available rules to customize colors
↑ Back to topYou can change the text color associated with each of the payment fields by using rules to target specific classes. With WooPayments, there are three classes that can be customized:
.Label
targets the label for the payment fields..Input
targets information customers add to the fields..Error
targets error messages that may result from incorrect or incomplete information.
Since the layout of the payment fields is consistent, these classes apply to all rendered elements.
Class Name | States | Pseudo-Classes |
---|---|---|
.Label | --empty , --invalid | |
.Input | --empty , --invalid | :hover , :focus , :disabled , :autofill |
.Error |
Using a filter to customize rule colors
↑ Back to topOnce you have determined which classes to modify, you can use the following filter to modify the color of the payment fields by replacing [CLASS]
and [VALUE]
with your desired modifications:
add_filter( 'wcpay_upe_appearance', function ( $appearance ) {
unset( $appearance->rules->{'[CLASS]'} );
$appearance->rules->{'[CLASS]'} = [
'color' => '[VALUE]',
];
return $appearance;
} );
For example, if you want to change the text users input to purple, you can use the following snippet:
add_filter( 'wcpay_upe_appearance', function ( $appearance ) {
unset( $appearance->rules->{'.Input'} );
$appearance->rules->{'.Input'} = [
'color' => 'purple',
];
return $appearance;
} );
You can expand on this a bit using the states, pseudo-classes, and pseudo-elements. For example, if you’d like the text color to change from purple to blue if the value is invalid, you can include an additional rule:
add_filter( 'wcpay_upe_appearance', function ( $appearance ) {
unset( $appearance->rules->{'.Input'} );
$appearance->rules->{'.Input'} = [
'color' => 'purple',
];
$appearance->rules->{'.Input--invalid'} = [
'color' => 'blue',
];
return $appearance;
} );
Clearing transients
↑ Back to topIn order for these appearance filters to display, you may need to clear the wcpay_upe_appearance
and wcpay_wc_blocks_upe_appearance
transients. While there is an option in Status > Tools to clear the WooCommerce transients, this tool will not clear these specific WooPayments transients.
The wcpay_upe_appearance
and wcpay_wc_blocks_upe_appearance
transients are automatically cleared after 24 hours. However, you can force them to be cleared using three different methods:
- Changing the site’s theme.
- Updating the WooPayments plugin.
- Executing the following PHP snippet once:
delete_transient( 'wcpay_upe_appearance' );
delete_transient( 'wcpay_wc_blocks_upe_appearance' );