<?php
/**
* Increment total entry number on each submission
*
* @link https://wpforms.com/developers/how-to-increment-a-count-on-each-form-submission
*/
function wpf_dev_update_total_field( $fields, $entry, $form_data ) {
$my_form_id = 1000; // Form ID to track
if( $form_data[ 'id' ] != $my_form_id ) {
return $fields;
}
$my_field_id = 15; // Hidden field ID to store count
$min_digits = 6; //Minimum digits in counter
// Count the entries and increment the hidden field count by 1 on each submit
$total_entries = wpforms()->entry->get_entries( array( 'form_id' => $my_form_id ), true );
$new_total_entries = $total_entries + 1;
// Add leading zeros and update field
$fields[ $my_field_id ][ 'value' ] = zeroise($new_total_entries, $min_digits);
add_filter( 'wpforms_process_filter', 'wpf_dev_update_total_field', 10, 3 );