更改 Woocommerce“积分和奖励”插件中显示的积分事件数量

问题描述 投票:0回答:2

我正在使用 WooCommerce“积分和奖励”插件为客户添加积分。 客户可以在他的账户中查看他的积分历史记录。 目前用户的帐户页面中仅显示 5 个点事件。

我在插件中找到了这个功能:

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

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

php wordpress woocommerce hook-woocommerce points
2个回答
1
投票

如您所见,您可以使用

wc_points_rewards_my_account_points_events
过滤器挂钩来更改显示的点数事件的数量,这样:

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
}

或者甚至更短一行:

add_filter( 'wc_points_rewards_my_account_points_events', function( $events, $user_id ){ return 20; }, 10, 2 );

代码位于活动子主题(或活动主题)的 function.php 文件中。已测试并有效。


0
投票

非常感谢您。它已经过测试并且有效。 我想知道是否有办法完全隐藏它们?

© www.soinside.com 2019 - 2024. All rights reserved.