Default value for a quantity field of a SingleProduct

Hi,
I can’t find where can I manage a default value for the “ginput_quantity” field of a SingleProduct?
In my case this field is empty and I want to set it to “0”.
NB: My products are generated dynamically in php with “GF_Field_SingleProduct” class.
Thanks for help.
Regards.

Hi @Klemart3D - can you create a gist or some other code share, so we can take a look at your code to see if it’s possible in your existing code, or if we need to do something else? Thank you.

Hi @chrishajer,

I was searching for something like a property of GF_Field_SingleProduct to define a default quantity:

	$singleProduct = new GF_Field_SingleProduct(
		array(
			'type'              => 'product',
			'id'                => '1001',
			'formId'            => $form['id'],
			'required'          => true,
			'label'             => 'My product label',
			'inputType'         => 'singleproduct',
			'allowsPrepopulate' => true,
			'default_quantity'  => 0, // => Or something like that
		)
	);

But it don’t works (my quantity fields are empty, not setted to 0), so I found a “workaround” by using “gform_field_value_default_quantity” hook (by enabling prepulation with “default_quantity” as name for quantity) :

add_filter( 'gform_field_value_default_quantity', 'default_quantity', 10, 2 );
function default_quantity( $sublabel, $form_id ) {
	return '0';
}

It would be nice to assign the default quantity value of a product directly inside the GF_Field object, it can be added?

Hi @Klemart3D - I will suggest that to the product team. I’m glad you found a workaround.