Is it possible to have a custom field in Webflow that tracks the number of credits a user has purchased and deducts a credit for each request?

Published on
September 22, 2023

Yes, it is possible to have a custom field in Webflow that tracks the number of credits a user has purchased and deducts a credit for each request. This functionality can be achieved through Webflow's CMS Collections feature and custom code.

To set this up, follow these steps:

  1. Create a CMS Collection: Go to your Webflow project and navigate to the CMS Collections tab. Create a new Collection and name it something like "Credits".

  2. Add Fields: Inside the "Credits" Collection, add two fields - "User" (linked to the Users Collection) and "Credit Count" (number field to track the number of credits).

  3. Create a Collection List: On the page where you want to display the credit count, drag and drop a Collection List element and bind it to the "Credits" Collection.

  4. Configure Collection List: Within the Collection List settings, filter the list to show the logged-in user only by adding a filter based on the currently logged-in user's ID.

  5. Display Credit Count: Inside the Collection List, add a Text element and bind it to the "Credit Count" field. This will display the number of credits for the logged-in user.

  6. Deduct Credits: To deduct credits for each request, you will need to use custom code. Add a custom code embed element to the page where the request is made.

  7. Write Custom Code: In the custom code embed element, write JavaScript code to fetch the current logged-in user's credit count, deduct one credit, and update the credit count in the CMS.

  8. Update the CMS with Custom Code: Use Webflow's API to update the CMS field for the logged-in user with the new credit count.

By following these steps, you can create a custom field in Webflow that tracks and deducts credits for each user request.

Additional Questions:

  1. How can I create a custom field in Webflow to track user credits?
  2. Can I use Webflow's CMS Collections to deduct credits for each user request?
  3. How do I use custom code to update a field in Webflow's CMS?