• Resolved envywigs

    (@envywigs)


    Is it possible to set the invoice option to only display for specific customers based on user role or some other parameter?

    • This topic was modified 1 year, 2 months ago by envywigs.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Jeff Alvarez

    (@superlemon1998)

    hi @@envywigs,

    You can use this snippet to disable the invoice payment gateway for specific customer roles, add the following through your child theme’s functions.php or through the WPCode plugin

    
     add_action('woocommerce_available_payment_gateways','Stop_Payment_Gateway');
    
     function Stop_Payment_Gateway($available_gateways){
    
    	 if(is_user_logged_in()){
    		global $current_user; 
    			if($current_user->roles[0] === "administrator"){
    				//stop invoice for admin customer
    				if(is_checkout()){
    				unset($available_gateways['igfw_invoice_gateway']); // Add the payment Code ID here
    				}
    			}
    		}
     
    	
    	 return $available_gateways;
     
     }
     
    

    To use the snippet simply change the administrator role to the role you wish to disable the invoice payment gateway.

    In this scenario first enable the payment gateway and then add the roles who aren’t supposed to view the said gateway.

    You can add multiple roles as such:

    if($current_user->roles[0] === "administrator" || $current_user->roles[0] === "subscriber" || $current_user->roles[0] === "role5"){
    //rest of the code goes here
    }
    • This reply was modified 1 year, 2 months ago by Jeff Alvarez.
    Thread Starter envywigs

    (@envywigs)

    Thank you for the update Jeff. Is it possible to only enable it for certain user roles (rather than excluding)? This would be much easier, as then I’d only have to go through and set up user roles for those who are allowed to use NET30 (far fewer than those excluded).?

    Plugin Author Josh Kohlbach

    (@jkohlbach)

    Hi @envywigs yep, you can do this by reversing the condition from === to !==

    It sounds like you might be using this for a wholesale/bulk situation? If so, our other plugin WooCommerce Wholesale Prices supports mapping payment gateways to wholesale user roles. You will need the Premium addon as well though as this is a premium feature.

    Hope this helps give you some options!

    Thread Starter envywigs

    (@envywigs)

    Josh, I’m not sure what you mean by “

    Hi @envywigs yep, you can do this by reversing the condition from === to !==“

    I created a new user role “net 30” that I want to ENABLE the invoice gateway for (this role only). The code provided says to “stop_payment_gateway”…. are there other components that should be updated??Thank you!

    add_action(‘woocommerce_available_payment_gateways’,’Stop_Payment_Gateway’);

    function Stop_Payment_Gateway($available_gateways){

     if(is_user_logged_in()){
    global $current_user; 
    if($current_user->roles[0] === “administrator”){
    //stop invoice for admin customer
    if(is_checkout()){
    unset($available_gateways[’igfw_invoice_gateway’]); // Add the payment Code ID here
    }
    }
    }


     return $available_gateways;

    }

    Plugin Support Jeff Alvarez

    (@superlemon1998)

    Hi @envywigs ,

    For the feature you had in mind to only allow the net30 role to have the invoice payment gateway, you’ll simply have to add a !== and in the code(if structure side) and update the admintrator to the appropriate role.

    The end product should look something like this

     add_action('woocommerce_available_payment_gateways','Stop_Payment_Gateway');
    
     function Stop_Payment_Gateway($available_gateways){
    
    	 if(is_user_logged_in()){
    		global $current_user; 
    			if($current_user->roles[0] !== "Net30"){
    				//stop invoice for everyone but Net30
    				if(is_checkout()){
    				unset($available_gateways['igfw_invoice_gateway']); // Add the payment Code ID here
    				}
    			}
    		}
     
    	
    	 return $available_gateways;
     
     }

    I would suggest double-checking what your Net30 role key is and updating accordingly in the code, It’s been bolded so simply change the bolded value. I’ve already edited the code so that the Invoice payment gateway is disabled for everyone but the specified role(Net 30)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Invoice Option Displayed based on User Role’ is closed to new replies.