The SR Restricted Content shortcode allows you to protect specific content anywhere on a page or post and only allow it to be seen after the customer has purchased a specific product.
To use the shortcode to protect content you will first need to create a product in WooCommerce that you want people to purchase before they have access to the content. You can name the product anything you’d like, but it’s best to keep it relevant to the content you are protecting, for example “VIP Access – Post 1”. Make sure the “Product data” is selected as “Simple product”, and select the “Virtual” product checkbox (this allows the customer to checkout without needing to enter their shipping address), then enter the price you want people to pay for access. Once the product has been published it will generate a product ID, you will need the product ID to add to the shortcode. You can find the product ID by looking at the URL address bar and where it says post=3178
for example, the number is the product ID. You can also find the product ID on the product list page, by hovering over the product title it will show the ID number below it.
Now that you have the product ID you can create a post or page and add the shortcode to it.
There are two shortcodes available to use, the first one shows public content that you want to be seen by everyone and then once they purchase the relevant product that content is replaced by the content in the other shortcode.
The First Shortcode – Public Content
This shortcode block is optional, but can be useful to show specific teaser content.
The shortcode is in two parts, an opening shortcode and a closing shortcode. Any content that is added between the opening and closing shortcode will be public, and hidden after the relevant product is purchased. There is a product_id attribute where you add the product ID for the product the customer needs to purchase, you can also use product_sku instead of product_id if you prefer to add SKUs to products (it is often easier to see what product has been added to the shortcode by seeing the SKU instead of an ID number).
[sr_show_content_before_purchase product_id="3178"]
The content I want to be public
[/sr_show_content_before_purchase]
The Second Shortcode – Protected Content
The shortcode is in two parts, an opening shortcode and a closing shortcode. Any content that is added between the opening and closing shortcode will be hidden, and only visible once the relevant product is purchased. You can use product_id or product_sku as above.
[sr_show_restricted_content_after_purchase product_id="3178"]
The content I want to sell, images, videos, text etc.
[/sr_show_restricted_content_after_purchase]
You can also change the default text for this shortcode by adding the follow attributes to the shortcode along with the product_id:
title="My Title"
If you add title="0"
no title will be shown.
purchase_message="My purchase message"
If you add purchase_message="0"
no purchase message will be shown.
purchase_button="My button text"
already_purchased_message="My already purchased message"
If you add already_purchased_message="0"
no already purchased message will be shown.
log_in_button="My log in text"
How to Add The Shortcode
To add a shortcode to a page or post, you can simply copy and paste the shortcode into the page content area. It will then automatically create the Shortcode block, sometimes it will not do this though, especially if adding the closing shortcode. So you can instead look for the little black plus square down the right side of the content area, or the little blue plus square at the top left of the page to select the block type you want to add. Type “shortcode” into the search box that opens and then you can select the Shortcode block to insert it into the page.
Copy and paste the shortcode into the Shortcode block, and don’t forget to change the product_id to your product ID! It should look something like this after you have added all the shortcodes:
This is public content, between the opening shortcode and closing shortcode.
Put the content you want to sell here, between the opening shortcode and closing shortcode.
You can alternatively also copy the below code directly into your post/page code editor to add all the necessary blocks and layout. To access the code editor, click the 3 little dots in the very top right hand corner of the post/page you are editing and select “Code editor”. Once you have copy pasted the below code you can exit the code editor. Then update the product_id to the correct product ID number and add your content to the SR Masonry Gallery block which is included in the below code, or replace it with a different block/content.
<!-- wp:shortcode --> [sr_show_content_before_purchase product_id=""] <!-- /wp:shortcode --> <!-- wp:paragraph {"align":"center"} --> <p class="has-text-align-center"><strong>See my exclusive content, only with VIP access!!</strong></p> <!-- /wp:paragraph --> <!-- wp:shortcode --> [/sr_show_content_before_purchase] <!-- /wp:shortcode --> <!-- wp:shortcode --> [sr_show_restricted_content_after_purchase product_id=""] <!-- /wp:shortcode --> <!-- wp:heading {"textAlign":"center","level":4} --> <h4 class="wp-block-heading has-text-align-center">Please enjoy my exclusive content below!</h4> <!-- /wp:heading --> <!-- wp:spacer {"height":"30px"} --> <div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div> <!-- /wp:spacer --> <!-- wp:lazyblock/sr-masonry-gallery {"blockId":"2jjNwP","blockUniqueClass":"lazyblock-sr-masonry-gallery-2jjNwP"} /--> <!-- wp:shortcode --> [/sr_show_restricted_content_after_purchase] <!-- /wp:shortcode -->
When the page or post is published, it will look something like this:
This is public content, between the opening shortcode and closing shortcode.
This content is restricted!
To view this content please purchase access by clicking the button below.
Purchase Access for £1,000Already Purchased? Log in to view content.
Log In