【问题标题】:How do I use specific filter hook for LearnDash WooCommerce plugin?如何为 LearnDash WooCommerce 插件使用特定的过滤器挂钩?
【发布时间】:2020-08-11 11:14:18
【问题描述】:

以下代码已通过 LearnDash WooCommerce 集成插件提供。

它会创建一个过滤器,使其能够在计费周期完成后禁止从课程中删除人员。我想默认打开它,这样用户就不会再从他们的课程中删除了。

如何在不更改插件代码的情况下应用此过滤器?

 /**
 * 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 );
}

【问题讨论】:

    标签: php wordpress woocommerce plugins wordpress-hook


    【解决方案1】:

    你可以使用

    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 );
    

    相关/来源:apply_filters( string $tag, mixed $value ) - 调用已添加到过滤器挂钩的回调函数。

    示例用法:

    // 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 );
    

    【讨论】:

      【解决方案2】:

      您可以简单地将WordPess __return_false 函数与此过滤器挂钩,以在计费周期完成后禁用从课程中删除人员,这样:

      add_filter( 'learndash_woocommerce_remove_course_access_on_subscription_billing_cycle_completion', '__return_false' );
      

      代码进入您的活动子主题(活动主题)的functions.php 文件中。它应该可以工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-13
        • 2020-01-02
        • 1970-01-01
        • 1970-01-01
        • 2021-10-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-06
        相关资源
        最近更新 更多