Filter
uncanny-automator
automator_stripe_price_name
Filters the name of a Stripe price before it's used in automations.
add_filter( 'automator_stripe_price_name', $callback, 10, 2 );
Description
Filters the generated price name for Stripe subscriptions. Modify the `$price_name` string before it's displayed, or use the `$price` array to create a custom name based on subscription intervals or nicknames. This hook fires after the default price name is constructed.
Usage
add_filter( 'automator_stripe_price_name', 'your_function_name', 10, 2 );
Parameters
-
$price_name(mixed) - This parameter contains the dynamically generated name for a Stripe price.
-
$price(mixed) - This parameter contains the generated name for the Stripe price, which is built from its nickname, unit amount, and currency.
Return Value
The filtered value.
Examples
// Add a custom suffix to the Stripe price name for annual recurring subscriptions.
add_filter( 'automator_stripe_price_name', function( $price_name, $price ) {
// Check if the price is recurring and the interval is 'year'.
if ( isset( $price['recurring']['interval'] ) && $price['recurring']['interval'] === 'year' ) {
$price_name .= ' (Annual)';
}
return $price_name;
}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/stripe/helpers/stripe-app-helpers.php:121
public function generate_price_name( $price ) {
$price_name = '';
if ( ! empty( $price['nickname'] ) ) {
$price_name .= $price['nickname'] . ' (';
}
if ( ! empty( $price['unit_amount'] ) ) {
$price_name .= $price['unit_amount'] / 100 . ' ' . $price['currency'];
}
if ( ! empty( $price['recurring'] ) ) {
$price_name .= ' per ' . $price['recurring']['interval'];
}
if ( ! empty( $price['nickname'] ) ) {
$price_name .= ')';
}
return apply_filters( 'automator_stripe_price_name', $price_name, $price );
}