【发布时间】:2017-03-24 16:07:06
【问题描述】:
我的functions.php 中有一些代码,您可以在下面看到。当我使用该操作挂钩时,该功能不会执行,但是当我挂钩过滤器时它会执行,有人可以解释为什么以及最佳做法是什么?
动作
// ADD £40 ON SUCCESFUL SUBSCRIPTION PAYMENT (EXAMPLE 1)
function custom_add_funds($user_id) {
// get current user's funds
$funds = get_user_meta( $user_id, 'account_funds', true );
// add £40
$funds = $funds + 40;
// add funds to user
update_user_meta( $user_id, 'account_funds', $funds );
}
add_action('processed_subscription_payment', 'custom_add_funds');
过滤器
// ADD £40 ON SUCCESFUL SUBSCRIPTION PAYMENT (EXAMPLE 2)
function custom_add_funds_two($user_id) {
// get current user's funds
$funds = get_user_meta( $user_id, 'account_funds', true );
// add £40
$funds = $funds + 40;
// add funds to user
update_user_meta( $user_id, 'account_funds', $funds );
}
add_filter('processed_subscription_payment','custom_add_funds_two');
【问题讨论】:
标签: wordpress