Recently a client had requested an events section on her website. Instead of using an overly complicated events plugin I decided to keep it simple and use a custom post type called “Events” and using Gravity Forms to accept payments on the Event page using Stripe. I also used the equally fantastic Advanced Custom Fields (ACF) plugin to create custom fields for the client so she can add prices, location, dates etc which will obviously differ on each event.
The problem I came across though was with the price. As we were using just one form across all events I needed the price to be dynamic across all events. So I created a custom field called “price” using ACF. I then needed to pass that value dynamically to the “Product” field in the form. Here is how I did it:
1. Add a hidden field to your form with {custom_field:price} merge tag set as default value.
2. Add a product field with calculation enabled and choose the hidden field from the previous step in the formula editor.
Thats it! So now any number you type in the Advanced Custom Field called “Price” that you created will auto-populate into the products price field.