Filter uncanny-automator-pro

automator_studiocart_sub_cancel_date

Filters the subscription cancellation date for StudioCart integrations, allowing modification before it's applied.

add_filter( 'automator_studiocart_sub_cancel_date', $callback, 10, 2 );

Description

Filters the cancellation date for a StudioCart subscription before it's used as a token. Developers can modify the date format or even completely change the date value being passed. Fires after the date is fetched and formatted using WordPress's internationalized date function.


Usage

add_filter( 'automator_studiocart_sub_cancel_date', 'your_function_name', 10, 2 );

Parameters

$value (mixed)
This parameter holds the formatted subscription cancellation date for display.
$sub (mixed)
This parameter represents the formatted cancellation date of the StudioCart subscription.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the automator_studiocart_sub_cancel_date hook.
 * This example adds 7 days to the subscription cancellation date if it exists.
 *
 * @param string|false $value The original cancellation date value.
 * @param object       $sub   The StudioCart subscription object.
 * @return string|false The modified cancellation date value, or false if no date exists.
 */
add_filter(
	'automator_studiocart_sub_cancel_date',
	function ( $value, $sub ) {
		// Check if a cancellation date exists and is a valid timestamp
		if ( ! empty( $value ) && is_numeric( $value ) ) {
			// Add 7 days to the cancellation date
			$new_date_timestamp = strtotime( '+7 days', $value );
			// Format the new date according to WordPress settings
			$value = date_i18n( get_option( 'date_format' ), $new_date_timestamp );
		}

		// Return the potentially modified value
		return $value;
	},
	10, // Priority
	2   // Accepted arguments
);

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

uncanny-automator-pro/src/integrations/studiocart/tokens/studiocart-pro-tokens.php:509

break;
							case 'sub_cancel_date':
								$value = $this->get_order_field_value( $sub, 'cancel_date' );
								if ( ! empty( $value ) ) {
									$value = date_i18n( get_option( 'date_format' ), $value );
								}

								$value = apply_filters( 'automator_studiocart_sub_cancel_date', $value, $sub );
								break;
							default:
								$token        = $parse;
								$token_pieces = $pieces;
								$value        = apply_filters( 'automator_studiocart_order_token_parser', $value, $token, $token_pieces, $sub );
						}
					}


Scroll to Top