'Hide some payment options when paying for an order from the WooCommerce account page
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.
Solution 1:[1]
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;
}
Solution 2:[2]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Syed Israr Ahmad |

