Skip to content

Instantly share code, notes, and snippets.

@growdev
Last active April 4, 2020 21:11
Show Gist options
  • Save growdev/4a1426305d0f425a5486 to your computer and use it in GitHub Desktop.
Save growdev/4a1426305d0f425a5486 to your computer and use it in GitHub Desktop.
Remove Unused Payment Gateways from Dashboard
<?php
add_filter( 'woocommerce_payment_gateways', 'growdev_remove_unused_payment_gateways', 20, 1 );
/**
* This function will remove all of the WooCommerce standard gateways from the
* WooCommerce > Settings > Checkout dashboard.
* @see current default gateways https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-payment-gateways.php#L77-L85
*/
function growdev_remove_unused_payment_gateways( $load_gateways ) {
$remove_gateways = array(
'WC_Gateway_BACS',
'WC_Gateway_Cheque',
'WC_Gateway_COD',
'WC_Gateway_Paypal'
);
foreach ( $load_gateways as $key => $value ) {
if ( in_array( $value, $remove_gateways ) ) {
unset( $load_gateways[ $key ] );
}
}
return $load_gateways;
}
@luiseduardobraschi
Copy link

Just change that loop for:
$load_gateways = array_diff( $load_gateways, $remove_gateways );

@coosamatt
Copy link

Any chance of getting this updated for 2019's default gateways?

@growdev
Copy link
Author

growdev commented Jun 10, 2019

@coosamatt Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment