如何解决如何为LearnDash WooCommerce插件使用特定的过滤器挂钩?
以下代码已通过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 );
}
解决方法
您可以使用
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',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',$arg2 );
,
您只需使用此过滤器钩子钩住WordPess __return_false
函数,即可在结算周期结束后通过以下方式禁止从课程中删除人员:
add_filter( 'learndash_woocommerce_remove_course_access_on_subscription_billing_cycle_completion','__return_false' );
代码进入您的活动子主题(活动主题)的functions.php文件中。应该可以。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。