title: Hide payment method if specific variation selected is blocking plugins
body: <p>I used this code for disabling the cod based on the sample from similar topic &quot;<a href="https://stackoverflow.com/questions/61434871/woocommerce-hide-payment-method-if-specific-variation-is-in-cart/71379876#71379876">Question 61434871</a>&quot;. It works but, when the snipped with this code snippet is enabled, it is blocking few plugins. For example the WP statistics or elementor editing are not working.</p>
  <pre><code>add_filter('woocommerce_available_payment_gateways', 'conditional_payment_gateways', 10, 1);
  function conditional_payment_gateways( $available_gateways ) {
  
      $in_cart = false;
          foreach ( WC()-&gt;cart-&gt;get_cart_contents() as $key =&gt; $values ) {
          // See if there is an attribute called 'pa_payment-method' in the cart
          // Replace with whatever attribute you want
              if (array_key_exists('pa_payment-method', (array) $values['data']-&gt;get_attributes() ) ) {
                  foreach ($values['data']-&gt;get_attributes() as $attribute =&gt; $variation);
                  // Replace 'on-site-pay' with your value.  
              if ($variation == 'on-site-pay') $in_cart = true; //edited
              } 
          }
      if ( $in_cart ) {
          unset($available_gateways['bacs']); // unset 'bacs' 
          unset($available_gateways['24pay_gateway']); // unset '24pay_gateway' 
      }
      else {
              unset($available_gateways['cod']); // unset 'cod' 
      }
  return $available_gateways;
  }
  </code></pre>