Created
August 10, 2020 14:56
-
-
Save andrewlimaza/fa951a8de922e2e3f9b37081624f62a4 to your computer and use it in GitHub Desktop.
Hide payment option for Wholesale Customers For WooCommerce Plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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