Filter
uncanny-automator
automator_surecart_price_type
Filters the price type for SureCart products, allowing for customization before it's applied.
add_filter( 'automator_surecart_price_type', $callback, 10, 2 );
Description
Filters the price type label for SureCart items. Developers can modify this label, for example, to change "Plan" to "Subscription" based on recurring intervals. This hook fires when determining the display text for a SureCart item's price type.
Usage
add_filter( 'automator_surecart_price_type', 'your_function_name', 10, 2 );
Parameters
-
$plan(mixed) - This parameter is not directly used within the provided function but is present in the hook signature.
-
$price(mixed) - This parameter represents the plan details, which are used to determine if the price is recurring.
Return Value
The filtered value.
Examples
/**
* Modify the SureCart price type string based on specific conditions.
*
* This function demonstrates how to hook into the 'automator_surecart_price_type'
* filter to customize the displayed price type for SureCart items within Uncanny Automator.
* For instance, we might want to append additional context for specific recurring
* subscription types.
*
* @param string $plan The current price type string (e.g., 'Plan', 'Subscription').
* @param object $price The SureCart price object, containing details about the price.
* @return string The modified price type string.
*/
add_filter( 'automator_surecart_price_type', function( $plan, $price ) {
// Check if the price object exists and has a specific recurring interval we want to highlight.
// For example, if it's a 'lifetime' subscription, we might want to explicitly label it.
if ( isset( $price->recurring_interval ) && 'lifetime' === $price->recurring_interval ) {
$plan = esc_html__( 'One-time Purchase (Lifetime)', 'uncanny-automator' );
}
// If the price is a subscription and has a trial period, we might want to denote that.
if ( isset( $price->recurring_interval ) && ! empty( $price->recurring_interval ) && isset( $price->trial_period_days ) && $price->trial_period_days > 0 ) {
$plan = sprintf(
esc_html__( '%s with %d-day Free Trial', 'uncanny-automator' ),
$plan, // This would already be 'Subscription' or 'One-time Purchase (Lifetime)' from previous checks
$price->trial_period_days
);
}
return $plan;
}, 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/surecart/tokens/surecart-tokens.php:530
src/integrations/surecart/tokens/surecart-tokens-new-framework.php:674
public function get_price_type( $price ) {
$plan = esc_html_x( 'One Time', 'Surecart', 'uncanny-automator' );
if ( ! empty( $price->recurring_period_count ) ) {
$plan = esc_html_x( 'Plan', 'Surecart', 'uncanny-automator' );
}
if ( ! empty( $price->recurring_interval ) ) {
$plan = esc_html_x( 'Subscription', 'Surecart', 'uncanny-automator' );
}
return apply_filters( 'automator_surecart_price_type', $plan, $price );
}