Quantcast
Channel: Snippets Archives - Gravity Wiz
Viewing all articles
Browse latest Browse all 196

Enable Decimal Values in Quantity Fields

$
0
0

Gravity Forms has some pretty comprehensive support for various pricing fields but one thing it does not provide is a weight field. So what do you do when you’re selling something by the pound?

This snippet will allow you to accept decimal values in Quantity fields; converting any Quantity field into a weight field!

View this code snippet on GitHub.

How do I install this snippet?

Easy peasy. Just paste it into your theme’s functions.php file.

Do I need to modify the snippet to work with my form?

Just a wee bit. You see the line at the very bottom of the snippet that looks like this:

new GW_Quantity_Decimal( 34, array( 1, 3 ) );

The first parameter is the $form_id for which this functionality should be enabled. The second parameter is an array of field IDs for which this functionality should be enabled.

If you want to enable this functionality on all product and quantity fields for a specific form, you would just do something like this (replacing the 34 with the ID of your form):

new GW_Quantity_Decimal( 34 );

If you want to enable this functionality for a single field on your form, initialize the class like this:

new GW_Quantity_Decimal( 34, 1 );

Summary

Now that your quantities can support decimal values, what else do you want to learn how to do with Gravity’s WordPress forms?


Viewing all articles
Browse latest Browse all 196

Trending Articles