When using Paid Memberships Pro’s Group Account Add On, you may choose to restrict group registrations to users with the same email domain as the Group Leader. This ensures all child accounts belong to the same organization, like a company or school, and prevents unauthorized users from joining.

This customization ensures that users checking out with a group code use an email address with the same domain as the group leader. 

Featured Image for Restrict Group Child Checkout Code Recipe

What is an email domain?

An email domain is the part of an email address after the @ symbol. For example, in [email protected], the domain is example.com. Organizations often require group members to share the same email domain to ensure only authorized users can register.

How does this code verify it?

This code enforces that rule by extracting the domain from both the group owner’s email and the registering user’s email. If the domains do not match, registration is blocked, and an error message is displayed. This ensures that only users with an approved domain can join the group, maintaining consistency and security.

Understanding the Code

This code recipe requires Paid Memberships Pro and the PMPro Group Accounts Add On to be installed and active.

When a user registers with a Group Code for a child account, this code checks whether their email domain matches the group leader’s (or parent). An error message appears if the domains do not match and checkout is blocked.

Screenshot of error message when domains do not match.

The Code Recipe

Using This Code Recipe

Add this code to your site by creating a custom plugin or using the Code Snippets plugin. If you are unfamiliar with custom plugins, refer to our guide on creating a plugin for PMPro customizations.

Customization

Update line 49 to change the text inside the pmpro_setMessage function to display your preferred error message.

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics
Was this article helpful?
YesNo