In this code recipe, we demonstrate how to run order creation checks before creating a user during the checkout process with Paid Memberships Pro v3.2 and higher.

This approach catches checkout issues early, preventing the creation of unnecessary user accounts. This is especially useful in reducing incomplete or problematic user accounts in your membership system.

Banner Image for the Prevent User Creation When There Are Issues in the Checkout Form Code Recipe Post

Why PMPro Creates Users First

Paid Memberships Pro’s checkout process now attempts to create a user every time there is enough user information to do so. While this may seem strange at the surface level, there are very good underlying reasons we do this:

  1. Speed Up Checkout for Users With Errors: By creating the user early, PMPro can save data related to their checkout attempts. If they need to fix any issues during the process (such as correcting a credit card number or missing information), their user information is already saved, making the flow much smoother when the form has errors.
  2. Cart Abandonment Campaigns: Early user creation allows you to leverage cart abandonment campaigns, where you can follow up with users who start the checkout process but fail to complete it. This is an excellent strategy for converting hesitant visitors into paying members.
  3. Prevent Issues with Account Registration: User creation before order completion also helps to prevent conflicts or issues that can arise if order data is tied to a user that doesn’t yet exist. This sequence simplifies the backend processes and reduces the risk of charging a potential member before we know there is a user to attach their membership site.
  4. Spam Detection and Cleanup: Although PMPro creates users early, we also have methods for detecting potential spam checkouts. This allows administrators to remove suspicious or incomplete accounts easily, keeping the user database clean.

In most cases, you should prefer this approach and leave the core functionality as-is. This process results in fewer disruptions for potential members, plus it gives you opportunities to bring them back even if their initial checkout failed.

Not everyone needs to use the approach in this code recipe—this customization is best for very specific cases where user creation must only happen after all checks are passed successfully.

Why Run Order Checks Before User Creation

Creating users at checkout before verifying all the necessary order details can lead to issues:

  • Incomplete User Accounts: Users may be created even when there are payment issues or missing information.
  • Admin Cleanup Hassles: If incomplete or incorrect data gets through, admins will have to manually clean up these user accounts later.

By running order checks before user creation, you can ensure that users are only created once their checkout details are validated properly.

About the Code Recipe

In this code recipe, we use the pmpro_checkout_user_creation_checks filter to delay user creation until after all relevant order checks have been completed. This keeps your membership database tidy by preventing unnecessary or erroneous user accounts from being generated.

  • If the checkout form contains issues, users will not be created.
  • However, orders will still be created before the payment step, even if payment then fails, allowing for proper logging of order attempts.

Understanding the pmpro_checkout_user_creation_checks Filter

The pmpro_checkout_user_creation_checks filter allows you to control when user creation happens during the checkout process.

With this code, you can make sure all order-related checks are completed successfully before creating a user.

The Code Recipe

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

Update the logic inside the my_pmpro_run_order_checks_before_user_creation() function to include additional checks, if needed. This flexibility allows you to tailor the order validation process to meet your specific membership site’s needs.

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