首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改Woocommerce“point &Reward”插件中显示的点事件数

更改Woocommerce“point &Reward”插件中显示的点事件数
EN

Stack Overflow用户
提问于 2018-05-09 15:32:04
回答 1查看 540关注 0票数 2

我正在使用WooCommerce "Points & Rewards“插件来向客户添加点数。顾客可以在他的帐户中查看他的观点的历史。目前,用户的帐户页面中只显示了5个点事件。

我在插件中找到了这个函数:

代码语言:javascript
复制
function woocommerce_points_rewards_my_points() {
    global $wc_points_rewards;

    $points_balance = WC_Points_Rewards_Manager::get_users_points( get_current_user_id() );
    $points_label   = $wc_points_rewards->get_points_label( $points_balance );

    $count = apply_filters( 'wc_points_rewards_my_account_points_events', 5, get_current_user_id() );

    // get a set of points events, ordered newest to oldest
    $args = array(
        'orderby' => array(
            'field' => 'date',
            'order' => 'DESC',
        ),
        'per_page' => $count,
        'paged'    => 0,
        'user'     => get_current_user_id(),
    );

    $events = WC_Points_Rewards_Points_Log::get_points_log_entries( $args );

    // load the template
    wc_get_template(
        'myaccount/my-points.php',
        array(
            'points_balance' => $points_balance,
            'points_label'   => $points_label,
            'events'         => $events,
        ),
        '',
        $wc_points_rewards->get_plugin_path() . '/templates/'
    );
}

有任何方法可以用自己的函数覆盖事件的数量吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-09 18:21:35

如您所见,您可以使用wc_points_rewards_my_account_points_events筛选器钩子来更改显示的点事件的数量,这样:

代码语言:javascript
复制
add_filter( 'wc_points_rewards_my_account_points_events', 'filter_wcpr_my_account_points_events', 10, 2 );
function filter_wcpr_my_account_points_events( $events, $user_id ) {
    return 20; // Change to 20 instead of 5
}

甚至在一行中更短:

代码语言:javascript
复制
add_filter( 'wc_points_rewards_my_account_points_events', function( $events, $user_id ){ return 20; }, 10, 2 );

代码在您的活动子主题(或活动主题)的function.php文件中。测试和工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50257081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档