Woocommerce

Change User Role After Purchasing Product

Do you restrict Content, Products, or other services on your site to certain membership level, until  User purchase a certain product or MemberShip plan from your WooCommerce Powered store?

But want to automate the process of changing User Role When an order is completed. with product id from ‘customer’ to ‘subscriber’ or any other membership level.

Too Easy… Just add the below code snippets in your theme’s functions.php file. ( Recommend to use Child Theme) and follow the instructions written below.

Code Snippet

Instructions:

The code on line  is a list of products to check,

Which means that script will check if one of the products purchased by the customer is in that list.

If yes, the user role will change to what you define on line 14.

Line 13 removes the customer’s old role, by default it’s Customer when they buy from you, but it could be different depends on your site settings.

If you want to remove more than one role, just duplicate the line and change the role slug.

 

Note: If you defined multiple role switches and the customer purchased more products that will change their role, only the first one found will switch their role.

Where to add this code?

You can place PHP snippets at the bottom of your functions.php file, We recommend to use child them so you will not lose any changes when updating your theme –.

Did this snippet work?

Please let us know in the comments if snippet worked as expected. We would be happy to revise the code if you report otherwise or in case you need more assistance.

Managing Memberships

Now you have the ability to change membership levels automatically but are you struggling to manage all the memberships. Why not make things easy?

WooCommerce Memberships works out of the box it’s not only restricting your site’s content: it’s simple, site-wide membership solution that brings your content, shop, and memberships together.

You can use this in addition to above code snippet in order to change membership levels automatically.

Watch the video below to understand the Power WooCommerce Membership Plugin

Some of the main Features (but not limited).

  • Membership plans are created independently from products.
  • Grant access to the same membership from several products (i.e., a yearly purchase or a monthly subscription)
  • Lets you schedule when your members should have access to content. For example, you can require that customers be a member for a 2 days before they can access certain posts or pages.
  • Can determine which content is included in a free trial period.
  • Lets you create members-only products.
  • Add your own notes for your reference for any Member for easy communication.
  • Expiration and renewal reminder emails
Show More

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close
Close