I am trying to pass a variable that I receive in an ajax call to an add_filter function.
Here is my code
add_action('wp_ajax_mht_set_partial_payment_amount', 'mht_set_partial_payment_amount');
add_action('wp_ajax_nopriv_mht_set_partial_payment_amount', 'mht_set_partial_payment_amount');
function mht_set_partial_payment_amount(){
$amount = $_POST["partial_payment_amount"];
add_filter('woo_wallet_partial_payment_amount', function($partial_payment){
return $amount;
}, 10, 1);
echo json_encode($amount);
die();
}
The $amount is completely okay in the response but it is not working at all in the filter.
I have tried many other ways to pass the $amount variable to the filter(using a class or a global variable) but nothing works.
The ajax call simply takes an input field value. And I need to pass the value to a filter.
I have spent hours on this but no luck :( Any help will be greatly appreciated!