Filter uncanny-automator-pro

automator_studiocart_sub_next_bill_date

Filters the next billing date for a Studio Cart subscription, allowing modification before it's saved.

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

Description

Filters the calculated next bill date for a StudioCart subscription before it's used as a token. Developers can modify this date, format it, or return a custom value. The `$value` parameter contains the date in a Unix timestamp format, and `$sub` is the subscription object.


Usage

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

Parameters

$value (mixed)
This parameter holds the calculated next billing date for the StudioCart subscription.
$sub (mixed)
This parameter contains the calculated next billing date for the StudioCart subscription, formatted according to the WordPress date format option.

Return Value

The filtered value.


Examples

<?php

/**
 * Example callback function to modify the next subscription billing date for StudioCart.
 *
 * This function demonstrates how to use the 'automator_studiocart_sub_next_bill_date'
 * filter to adjust the displayed next billing date.
 *
 * @param string|false $value The current next billing date string, or false if not set.
 * @param object       $sub   The StudioCart subscription object.
 *
 * @return string|false The modified next billing date string, or false.
 */
function my_custom_studiocart_next_bill_date( $value, $sub ) {

    // Example: Add an extra day to the next billing date if it's a weekend.
    if ( $value && is_string( $value ) ) {
        // Attempt to get the timestamp from the formatted date.
        // This assumes the original value was a timestamp and then formatted.
        // A more robust solution might directly access the timestamp if available from $sub.
        $timestamp = strtotime( $value );

        if ( $timestamp ) {
            $day_of_week = date( 'N', $timestamp ); // 1 = Monday, 7 = Sunday

            // If it's Saturday (6) or Sunday (7)
            if ( $day_of_week >= 6 ) {
                // Add two days to move it to Monday
                $new_timestamp = $timestamp + ( 2 * DAY_IN_SECONDS );
                $value = date_i18n( get_option( 'date_format' ), $new_timestamp );
            }
        }
    }

    // You could also check for specific subscription IDs or product IDs
    // if ( isset( $sub->ID ) && $sub->ID === 123 ) {
    //     // Do something specific for subscription 123
    // }

    return $value;
}

// Add the filter with a priority and accepting 2 arguments
add_filter( 'automator_studiocart_sub_next_bill_date', 'my_custom_studiocart_next_bill_date', 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

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

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

								$value = apply_filters( 'automator_studiocart_sub_next_bill_date', $value, $sub );
								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 );
								}


Scroll to Top