automator_surecart_amount
Filters the SureCart transaction amount before it is processed.
add_filter( 'automator_surecart_amount', $callback, 10, 2 );
Description
Filters the formatted SureCart amount and currency string. Developers can use this to modify the displayed price, such as adding prefixes, suffixes, or changing the currency symbol, before it's presented in Automator workflows.
Usage
add_filter( 'automator_surecart_amount', 'your_function_name', 10, 2 );
Parameters
-
$amount(mixed) - The `$amount` parameter is the formatted monetary value of the SureCart price.
-
$price(mixed) - This parameter represents the formatted monetary amount derived from the SureCart price object.
Return Value
The filtered value.
Examples
add_filter( 'automator_surecart_amount', 'my_custom_surecart_amount_display', 10, 2 );
/**
* Modifies the displayed SureCart amount for specific automations.
*
* This function allows you to customize how the amount is displayed
* when it's used as a token in Uncanny Automator. For instance,
* you might want to add a prefix or suffix, or format it differently.
*
* @param string $amount The default formatted amount string (e.g., "10.00 USD").
* @param object $price The SureCart price object, containing details like amount, currency, and recurring settings.
* @return string The modified amount string.
*/
function my_custom_surecart_amount_display( $amount, $price ) {
// Example: Add a custom prefix if the price is over a certain threshold.
if ( floatval( $price->amount ) > 50 ) {
$amount = 'Premium: ' . $amount;
}
// Example: If it's a recurring price, append a different indicator.
if ( ! empty( $price->recurring_interval ) ) {
$amount .= ' (Recurring)';
}
return $amount;
}
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/surecart/tokens/surecart-tokens.php:493
src/integrations/surecart/tokens/surecart-tokens.php:509
src/integrations/surecart/tokens/surecart-tokens-new-framework.php:637
src/integrations/surecart/tokens/surecart-tokens-new-framework.php:653
public function get_amount( $price ) {
$amount = $this->format_amount( $price->amount );
$amount .= ' ' . $price->currency;
$amount = apply_filters( 'automator_surecart_amount', $amount, $price );
if ( ! empty( $price->recurring_interval ) ) {
$interval = $this->get_interval_string( $price->recurring_interval, $price->recurring_interval_count );
// translators: 1. recurring count 2. recurring interval.
$amount .= ' ' . sprintf( esc_html_x( 'every %1$d %2$s', 'Surecart', 'uncanny-automator' ), $price->recurring_interval_count, $interval );
}
if ( ! empty( $price->recurring_period_count ) ) {
$interval = $this->get_interval_string( $price->recurring_interval, $price->recurring_period_count );
// translators: 1. period count 2. recurring interval.
$amount .= sprintf( ' for %1$d %2$ss', $price->recurring_period_count, $price->recurring_interval );
}
return apply_filters( 'automator_surecart_amount', $amount, $price );
}