Gravity Forms offers an excellent multi-file upload field to attach multiple files such as images to a form submission. I have used the WooCommerce Gravity Forms Add-on to add complex functionality to WooCommerce products, for example allowing customers to upload images for printing. But what happens if you want to count the number of uploaded files? Say you want to price your product based on the number of uploaded files to be processed. Normally you will need to calculate the price based on a quantity field entered by the customer since Gravity Forms does not make the number of files uploaded to a multi-file upload field available to the form. This creates a margin for error since the customer may enter the incorrect number in the quantity field.
- The code should be placed in your theme’s functions.php.
- You will need to set the form ID of your form in line 6.
- You will need to set the field ID of your uploaded files count field in line 50.
- You will need to add a custom CSS class of ‘gf_readonly’ to your uploaded files count field in the form editor.