skip to Main Content

The following code has been supplied through the LearnDash WooCommerce integration plugin.

It creates a filter which makes it able to disable removing people from courses after the billing cycle is complete. I want to turn this on by default, so that users aren’t removed from their course anymore.

How can I apply this filter, without changing the plugin code?

 /**
 * Get setting if course access should be removed when user completeng subscription payment billing cycle
 *
 * @param  object $subscription WC_Subscription object
 * @return boolean
 */
public static function is_course_access_removed_on_subscription_billing_cycle_completion( $subscription )
{
    return apply_filters( 'learndash_woocommerce_remove_course_access_on_subscription_billing_cycle_completion', false, $subscription );
}

2

Answers


  1. You could use

    function my_callback_function ( $access, $subscription ) {
        $access = true;
        return $access;
    }
    add_filter( 'learndash_woocommerce_remove_course_access_on_subscription_billing_cycle_completion', 'my_callback_function', 10, 2 );
    

    Related/Source: apply_filters( string $tag, mixed $value ) – Calls the callback functions that have been added to a filter hook.

    Example usage:

    // The filter callback function.
    function example_callback( $string, $arg1, $arg2 ) {
        // (maybe) modify $string.
        return $string;
    }
    add_filter( 'example_filter', 'example_callback', 10, 3 );
    
    /*
     * Apply the filters by calling the 'example_callback()' function
     * that's hooked onto `example_filter` above.
     *
     * - 'example_filter' is the filter hook.
     * - 'filter me' is the value being filtered.
     * - $arg1 and $arg2 are the additional arguments passed to the callback.
     */
    $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );
    
    Login or Signup to reply.
  2. You can simply hook the WordPess __return_false function with this filter hook, to disable removing people from courses after the billing cycle is complete, this way:

    add_filter( 'learndash_woocommerce_remove_course_access_on_subscription_billing_cycle_completion', '__return_false' );
    

    Code goes in functions.php file of your active child theme (active theme). It should work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search