I have some code in my functions.php which you can see below. When I hook in using the action the function doesn't execute, but when I hook into the filter it does, could someone explain why and whats the best practice?
ACTION
// 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');
FILTER
// 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');