Filter
uncanny-automator
automator_surecart_token_product_download_url_expiration
Filters the expiration time for SureCart product download URLs, allowing customization of download link validity.
add_filter( 'automator_surecart_token_product_download_url_expiration', $callback, 10, 2 );
Description
Filters the expiration time for SureCart product download URLs, allowing customization of how long download links remain valid. Developers can modify the default 24-hour expiration to offer shorter or longer access periods based on specific product or purchase requirements.
Usage
add_filter( 'automator_surecart_token_product_download_url_expiration', 'your_function_name', 10, 2 );
Parameters
-
$download(mixed) - This parameter represents the default expiration time in seconds for SureCart download tokens, defaulting to 24 hours.
-
$purchase_data(mixed) - This parameter represents the generated download URL for a product.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the expiration time for SureCart product download URLs.
* This example reduces the default expiration from 24 hours to 1 hour.
*/
add_filter( 'automator_surecart_token_product_download_url_expiration', function( $expiration_time, $download_item, $purchase_data_details ) {
// Reduce the expiration time to 1 hour (3600 seconds)
$new_expiration_time = 60 * 60;
// You could also add conditional logic here, for example:
// if ( $purchase_data_details->total < 50 ) {
// $new_expiration_time = 60 * 30; // 30 minutes for orders under $50
// }
return $new_expiration_time;
}, 10, 3 );
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:573
src/integrations/surecart/tokens/surecart-tokens-new-framework.php:717
public function get_download_urls( $purchase_data ) {
$downloads = $this->get_downloads( $purchase_data );
$download_urls = array();
if ( empty( $downloads ) ) {
return '';
}
foreach ( $downloads as $download ) {
$expose_for = apply_filters( 'automator_surecart_token_product_download_url_expiration', 24 * 60 * 60, $download, $purchase_data );
$media = SureCartModelsMedia::where( array( 'expose_for' => $expose_for ) )->find( $download->media->id );
$download_urls[] = $media->url;
}
return implode( ', ', $download_urls );
}