Filter uncanny-learndash-groups

learndash_woocommerce_remove_group_access_on_subscription_billing_cycle_completion

Filters whether to remove LearnDash group access when a WooCommerce subscription billing cycle completes.

add_filter( 'learndash_woocommerce_remove_group_access_on_subscription_billing_cycle_completion', $callback, 10, 1 );

Description

Filters whether LearnDash should automatically remove group access when a WooCommerce subscription's billing cycle completes. Return `true` to enable removal, `false` (default) to disable it. This is useful for controlling course access duration based on subscription payments.


Usage

add_filter( 'learndash_woocommerce_remove_group_access_on_subscription_billing_cycle_completion', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Determines whether to remove LearnDash group access when a WooCommerce subscription billing cycle completes.
 *
 * By default, this filter returns `false`, meaning access is NOT removed.
 * This example shows how to change that behavior to remove access.
 *
 * @param bool $remove_access Whether to remove group access. Default false.
 * @return bool True to remove group access, false otherwise.
 */
add_filter( 'learndash_woocommerce_remove_group_access_on_subscription_billing_cycle_completion', function( $remove_access ) {
    // Check if WooCommerce is active and if the current user has a subscription
    // that should trigger the removal of group access.
    if ( class_exists( 'WooCommerce' ) && ! is_admin() ) {
        // This is a simplified example. In a real-world scenario, you would
        // need to integrate with WooCommerce Subscriptions to accurately
        // determine if a subscription has reached a billing cycle completion
        // that warrants group access removal.
        // For instance, you might check for a specific subscription status
        // or a meta field indicating completion.

        // Let's assume for this example that we want to remove access if
        // a specific meta key 'should_remove_group_access_on_completion'
        // is set to true on the subscription.
        // You would retrieve this meta data within the context of the subscription.

        // Example placeholder:
        $some_subscription_condition_met = false; // Replace with actual logic to check subscription status

        if ( $some_subscription_condition_met ) {
            return true; // Remove group access
        }
    }

    return $remove_access; // Keep the default behavior or return the modified value
}, 10, 1 );

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/classes/woocommerce/woocommerce-learndash-groups.php:671

public static function is_group_access_removed_on_subscription_billing_cycle_completion() {
		return apply_filters( 'learndash_woocommerce_remove_group_access_on_subscription_billing_cycle_completion', false );
	}


Scroll to Top