Hi friends, I’m hoping someone more knowledgeable than myself about Pro Forms can chime in with some assistance.
I’ve created an order form using the Pro Form
I need to have a auto-generated Order Number created each time the form is submitted
This Order Number needs to be unique, for example starting with 105, each time the form is summited it will generated the next sequential number plus add the current year to the back, i.e., 1052024, 1062024, etc…
This auto generated number needs to be included in the confirmation email that goes to the customer for reference purposes.
How do I incorporate this solution into the Pro Form? I thought I could use an invisible field to place the PHP code, but I’m not seeing how I can since the only query option is to “echo” a single line of PHP.
Any other suggestions or approaches to how I might accomplish generating unique Order Numbers is in my order form are greatly appreciate.
You should not handle this on the client side, because while the user is filling out the form, others may already have been sent. This would then result in an incorrect sequence.
You can use the “Custom” action for such individual things. There you can execute individual code that is executed as soon as the form has been submitted.
Edit to add that I’m attempting a more simplified approach with this single line of PHP, however I’m still not clear how I would include this in the form?
Update - I’ve added this as a function that can be placed as a shortcode (tested and works).
So my updated question is - what is the best method to include the shortcode in the form so that the random Order Number that’s generated is also included in the confirmation email sent to the submitter?
You can just create a custom function in your child theme functions.php and then use the dynamic data tag {echo:your-fuction} just like you would with other DD tags. In your case you can use the echo tag as the value of a hidden field so the data gets sent in the form. Dynamic Data – Bricks Academy
Did you allow the function name? There was info in about it the other link but you might have missed it. Here’s the code snippet you have to add to make it work: Then you have to sign it in the Bricks settings. It’s kind of pain but Bricks makes you do this for security reasons. Filter: bricks/code/echo_function_names – Bricks Academy
If you need a unique number keep in mind that random numbers are not unique. They can repeat, especially if you choose a small number between 0 and 9999. You could save the submissions to the DB and increase the values by one each time a form is submitted.
I agree. This is a little outside of my very basic capabilities with PHP. If you could explain how to do this in ELI5 fashion, it would be most appreciated.
At the moment I’m having orders populate to a Google Sheet.
Edit to add, I think I’ve figured it out:
function create_unique_numbers_table() {
global $wpdb;
$table_name = $wpdb->prefix . 'unique_numbers';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
number varchar(9) NOT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY number (number)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
add_action('plugins_loaded', 'create_unique_numbers_table');
An easier no code method would be to create a custom field to store the number of orders submitted and then use the update post meta action set to increment number so that every time it’s submitted the number is updated.