Lodaer Img

payment separarating for different cattegoryes of clients

This code checks the role of the current user and removes the bank transfer payment method (BACS) from the available payment methods if the user has a specific role. You need to replace ‘customer’ with the desired user role for which you want to disable bank transfer payment.

 

Open the WordPress admin area.

Go to “Appearance” -> “Editor”.

Find and open the functions.php file of your current theme.

Add the above code to the end of the file.

Save the changes.

After that, the bank transfer payment system will not be available for the specified user type.

				
					add_filter( 'woocommerce_available_payment_gateways', 'disable_bacs_for_specific_user' );

function disable_bacs_for_specific_user( $available_gateways ) {
    // Get the current user
    $user = wp_get_current_user();
    
    // Specify the user type for which to disable the payment gateway
    $restricted_user_type = 'customer'; // Replace with the desired user type
    
    // Check if the user has the specified role
    if ( in_array( $restricted_user_type, (array) $user->roles ) ) {
        // Remove the bank transfer payment method
        if ( isset( $available_gateways['bacs'] ) ) {
            unset( $available_gateways['bacs'] );
        }
    }

    return $available_gateways;
}
				
			
Portfolio Details

Пожалуйста, отправьте нам запрос.

    Veuillez nous envoyer une demande de renseignements.

      Please send us an enquiry.