// Show/hide payment gateways add_filter( 'woocommerce_available_payment_gateways', 'conditionally_hide_payment_gateways', 100, 1 ); function conditionally_hide_payment_gateways( $available_gateways ) {     // 1. On Order Pay page     if( is_wc_endpoint_url( 'order-pay' ) ) {         // Get an instance of the WC_Order Object         $order = wc_get_order( get_query_var('order-pay') );          // Loop through payment gateways 'pending', 'on-hold', 'processing'         foreach( $available_gateways as $gateways_id => $gateways ){             // Keep paypal only for "pending" order status             if( $gateways_id !== 'paypal' && $order->has_status('pending') ) {                 unset($available_gateways[$gateways_id]);             }         }     }     // 2. On Checkout page     elseif( is_checkout() && ! is_wc_endpoint_url() ) {         // Disable paypal         if( isset($available_gateways['paypal']) ) {             unset($available_gateways['paypal']);         }     }     return $available_gateways; } 

Read more of this post