cant't access $_POST throw woocommerce_available_payment_gateways hook

Viewed 28

I need to unset the payment gateway in the checkout page based on the selected custom radio button on the Cart page in Woocommerce with "woocommerce_available_payment_gateways" hook, I tried to catch it from $_POST but I can't access $_POST after "?wc-ajax=update_order_review" happened here is my code:

    add_filter('woocommerce_available_payment_gateways', 'filter_gateways', 1);
function filter_gateways($gateways)
{
  if (is_admin())
    return $gateways;


  switch ($_POST['selected_example_gateway']) {
    case '1': {
        unset($gateways['example1']);
        break;
      }
    case '2': {
        unset($gateways['example1']);
        break;
      }
  }
  return $gateways;
}

I try to use "query_vars" filter but it's not working too

add_filter('query_vars', 'sgh_query_vars');
function sgh_query_vars($vars)
{
  $vars[] = 'selected_example_gateway';
  return $vars;
}




    ...
// here is how I'm  getting query_var 
        get_query_var('selected_example_gateway')
    ...

it's working fine without the $_POST condition also It worked before fragment refresh happen.

0 Answers
Related