在wordpress中使用add_filter覆盖插件

xcitsw88  于 2022-11-02  发布在  WordPress
关注(0)|答案(1)|浏览(176)

所以我找到了这个

$points_to_award = (int) apply_filters( 'gamipress_wc_points_per_purchase_total_points_to_award', $points_to_award, $user_id, $points_type, $order_id, $percent );

在插件代码里面,我怎么能用这个来覆盖$points_to_award的值呢?2在我的function.php里面使用add_filter?
我试过:

function my_custom_function($points_to_award) {
$points_to_award = ($order->get_total() - $order->get_shipping_total()) * ($ratio/100);
        return $points_to_award; 
}
add_filter( 'gamipress_wc_points_per_purchase_total_points_to_award', 'my_custom_function' );

但没有用

ljsrvy3e

ljsrvy3e1#

您需要获取订单ID和比率,如下所示

function my_custom_function($points_to_award, $user_id, $points_type, $order_id, $ratio) {
    $order = wc_get_order( $order_id );
    $points_to_award = ($order->get_total() - $order->get_shipping_total()) * ($ratio/100);
    return $points_to_award; 
}
add_filter( 'gamipress_wc_points_per_purchase_total_points_to_award', 'my_custom_function', 10, 5 );

相关问题