Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created August 10, 2020 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewlimaza/fa951a8de922e2e3f9b37081624f62a4 to your computer and use it in GitHub Desktop.
Save andrewlimaza/fa951a8de922e2e3f9b37081624f62a4 to your computer and use it in GitHub Desktop.
Hide payment option for Wholesale Customers For WooCommerce Plugin.
<?php
/**
* Hide payment gateways for wholesale customers.
* Add this code to your site via a custom plugin or the Code Snippets Plugin.
* Adjust line 18 with payment gateway ID's you wish to hide from wholesale customers.
* Reference: https://yoohooplugins.com/woocommerce-wholesale-customers-payment-gateway/
*/
function yoohoo_wcs_hide_gateways( $available_gateways ) {
global $current_user;
$is_wholesale = get_user_meta( $current_user->ID, 'wcs_wholesale_customer', true );
if ( ! $is_wholesale ) {
return $available_gateways;
}
$hide_payments = array( 'cod', 'bacs' ); //Add payment gateway ID's/slugs here.
foreach( $hide_payments as $gateway ) {
if ( isset( $available_gateways[$gateway] ) ) {
unset( $available_gateways[$gateway] );
}
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'yoohoo_wcs_hide_gateways' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment