skip to Main Content

If the order has the Pending payment status, then the user can pay for it on the account page. This displays all available payment options. How to hide all payment methods except checks? I did it with CSS, but I would like to do it with a hook.

2

Answers


  1. disable the other payment methods from woo-commerce<<settings<<payment
    like this

    Login or Signup to reply.
  2. add_filter('woocommerce_available_payment_gateways', 'custom_available_payment_gateways');
    
    function custom_available_payment_gateways($available_gateways) {
    
        $payment_ids = array('paypal'); // Here define the allowed payment methods ids to keep ( cod, stripe ... )
        
        // For Order pay
        if (is_wc_endpoint_url('order-pay')) {
    
            foreach ($available_gateways as $payment_id => $available_gateway) {
                if (!in_array($payment_id, $payment_ids)) {
                    unset($available_gateways[$payment_id]);
                }
            }
        }
    
        return $available_gateways;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search