Home > other >  Hide some payment options when paying for an order from the WooCommerce account page
Hide some payment options when paying for an order from the WooCommerce account page

Time:05-03

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.

CodePudding user response:

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

CodePudding user response:

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;
}
  • Related