从 WooCommerce 帐户页面支付订单时隐藏一些支付选项

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

如果订单状态为Pending payment,则用户可以在账户页面进行支付。这将显示所有可用的付款选项。如何隐藏支票以外的所有付款方式?我是用CSS做的,但我想用钩子做。

woo-commerce<禁用其他支付方式

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