If you would like to change the user role only when specific products are in the order, you will need the product IDs ready.
Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.
Need support with the snippet? We’re Here to Help You, Contact Us!
This snippet will automatically change the role of users who complete a purchase for specific products. Specific to this example, is any one of the three product IDs defined in the code are in the other, the “Customer” role of the buyer will be removed, and a new role added, “Subscriber”. Be careful using this snippet, you don’t want to inadvertently give customers the ability to edit your store! You can make this code work so that all customers, regardless of the products bought, have a new role – that is a case of removing the if statement and foreach loop. Keep in mind, the role is only changed when the order status is set to Complete (this too can be done automatically as shown in this guide).
Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.