How to Set Up a Pay-Per-Post Form in WordPress

When running a membership or premium content website, you may want to restrict access to certain posts and require users to unlock them by making a payment. A Pay-Per-Post form makes this possible by connecting each user to the specific content they purchase. 

In this guide, you will learn how to create a Pay-Per-Post form in the JetFormBuilder WordPress plugin. The form is placed on the single post page, and once the user submits it, they are redirected to the payment gateway. After a successful transaction, the user is automatically connected to the purchased post and can view its content. Non-paying visitors, on the other hand, see restricted access.

Tutorial Requirements:

Table of Contents:

Set Up the Relations

First, the relations between the Custom Post Type and users should be set. This will allow to connect users with the posts for which they pay. In this case, we connect the “Courses” CPT to users.

cpt to users relation created

Click the “Add Relation” button.

Create a Form

Now, let’s proceed to setting up a form. To build a WordPress form, we navigate to WordPress Dashboard > JetFormBuilder > Add New Form

Enter the form’s title — in this case, it is “Pay-per-Post Form”.

The Welcome block appears by default. From here, you can select a form pattern or generate a form with OpenAI. Otherwise, you can hit the “Start from scratch” button and use the three fields added by default; otherwise, you can delete them to begin anew.

In this case, we build our form from scratch. We also delete the default fields. For this, we add two Hidden Fields for the current post ID and current user ID, a Number Field for the price, and the Action Button.

form fields set up
NOTE

It is important for users to be registered on the site. You can set the Register User form with JetFormBuilder or register users in any other way that is appropriate for you.

In the Gateways Settings tab, we check the PayPal Checkout option. Refer to our PayPal Recurring Payments guide to know how to set up the payments functionality. 

gateways settings

Open the JetForm > Post Submit Actions tab and press the “+ New Action” button. In the opened pop-up, find and click the “Connect Relation Items” action to add it.

Now, you should see a pop-up that provides the settings for this action. Select the RELATION, set the “post_id” field for the PARENT ITEM ID, and the “user_id” for the CHILD ITEM ID. Leave the UPDATE CONTEXT field empty. In the HOW TO STORE NEW ITEMS field, you can select the most appropriate choice for you. When you finish, press the “Update” button.

connect relations submit action set up

Then click the “Edit Conditions & Events” button next to the “Connect Relation Items” action. Proceed to the Events match tab and search for the “GATEWAY.SUCCESS” event in the ADD EVENT field. 

gateway added to the action

Click the “Update” button. 

Once you are ready with the form settings, click the “Publish” button.

Add the Form to the Page

Now, proceed to the single page of the CPT you need to sell access to (“Courses” in this case). 

For this case, we keep some data of the post hidden until the user pays for it. For this, we use the Dynamic Visibility functionality. 

For this, we use the “In the list” Condition. For the Field, we select the “Related Items” option from the Dynamic Tags and choose the relation we created earlier. For the Value input, select the “Macros” option from the Dynamic Tags and choose the “Current user ID”.

dynamic visibility settings for the posts data

Following the How to Display a Form on the Front End guide, we added the form to the page. 

To show the form only until the user pays, we apply the same Dynamic Visibility rules, except for the “Hide element if condition met” in the Visibility condition type.

dynamic visibility for the form

Click the “Publish” button once you are ready with the settings.

Check the Result

Let’s proceed to the front end page. Before the post is connected to the user through relations, the content is hidden, and the form is visible. 

form on the front

After the form is submitted, the user pays, and the relationship between the post and the current user is established, the content becomes accessible to the user.

posts content on the front

That’s it. Now you know how to restrict access to certain posts and require users to unlock them by making a payment using the WordPress JetFormBuilder plugin.