Skip Navigation

[Resolved] Pay to view more content

This thread is resolved. Here is a description of the problem and solution.

Problem:

I need your advice if I can do it with Toolset, see details here:

https://toolset.com/forums/topic/pay-to-view-more-content/#post-1176409

Solution:

There isn't exact feature within Toolset plugins, it might involve custom codes. Here are my suggestions:

https://toolset.com/forums/topic/pay-to-view-more-content/#post-1176752

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by deanL 5 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1176409

I'm starting a new project and I would like to achieve the following. I need your advice if I can do it with Toolset.

1. I will use CPT for creating content pages
2. Users can only view partial content on the page
3. In order to view full content, users need to spend a credit — however, the credit limits access only to the said page; to view other pages, users spend credits accordingly
4. Users can buy and pay for blocks of credits
5. Credits expire after 1 year

Let me know if above makes sense?

#1176752

Hello,

There isn't exact feature within Toolset plugins, it might involve custom codes.
Here are my suggestions:
1) Create two custom user fields
- Credits (numeric field, use it to store user's Credits value)
- Credit expire date (date field, use it to store Credit expiration date)
https://toolset.com/documentation/user-guides/user-fields/

2) Create two custom post types:
a) Your CPT(Parent post type), with some custom fields:
- Public view field
- Private view field
b) Pay record CPT(Child post type)
setup one-to-many relationship between post types "Your CPT" and "Pay record CPT"

3) In a single "Your CPT" post content, display the "Public view field" + below post view

4) Create a post view, query "Pay record CPT", filter by:
- Posts are related with current "Your CPT" post
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
- post's author is current logged-in user,
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/
- post status is published:
https://toolset.com/forums/topic/post-status-filter-select/

If there is any post found, display "Private view field" value of "Your CPT" post
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent

If there isn't any post found, display below Toolset post form

5) Create a post form for creating "Pay record CPT" post, save the new post in "draft" status
https://toolset.com/documentation/user-guides/using-cred-commerce-to-add-payments-to-forms/

6) After user submit above post form, use action hook "cred_save_data" to trigger a PHP function
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

In this PHP function, check if current user has enough "Credits" in his "Credits" user field, and deduct the specific value from "Credits" user field, then update the new "Pay record CPT" post as published status. More help:
https://developer.wordpress.org/reference/functions/get_user_meta/
https://developer.wordpress.org/reference/functions/update_user_meta/
https://developer.wordpress.org/reference/functions/wp_update_post/

7) Create a WordPress CRON job, get user's "Credit expire date" field value, compare with current date value, if it is expired, update "Credits" user field value as zero.
https://developer.wordpress.org/plugins/cron/

For your reference.

#1178146

Thank you Luo Yang for the suggested solution. It looks good until the PHP and cron parts. I eventually found a plugin that does what I needed. Will give that a shot first: hidden link

Thank you for your time, nevertheless!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.