# Make quantity field optional

**URL:** <https://community.hivepress.io/t/make-quantity-field-optional/11782>\
**Category:** Marketplace\
**Tags:** marketplace\
**Created:** [August 8, 2024, 1:41pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782 "2024-08-08T13:41:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 8, 2024, 1:41pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/1 "2024-08-08T13:41:54Z")

</div>

The following snippet does not work when applied to the ‘quantity’ attribute/field:

```auto
add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) 
	{
		if ( isset( $attributes['quantity'] ) ) 
		{
			$attributes['quantity']['edit_field']['required'] = false;
		}
		return $attributes;
	},
);

```

Likewise, the following snippet does not work when applied to the ‘extras’ attribute/field:

```auto
add_filter(
	'hivepress/v1/forms/listing_update',
	function( $form ) {
		$form['fields']['extras']['label'] = 'shipping options';

		return $form;
	},
	1000
);

```

Both snippets work when applied to other listing attributes/fields.

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [August 9, 2024, 8:32am UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/3 "2024-08-09T08:32:54Z")

</div>

Hi,

Please make sure you add these snippets using this doc: [How to add custom code snippets - HivePress Help Center](https://help.hivepress.io/article/23-how-to-add-custom-code-snippets). Also, please disable third-party plugins and customizations (if there are any) and check if this issue persists. If you use a caching plugin, make sure that caching is disabled for logged-in users.

​I hope this is helpful to you.

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 9, 2024, 9:14am UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/4 "2024-08-09T09:14:39Z")

</div>

Thanks for the reply, however this does not help.

As I said, the snippets work fine in general, but for specific fields (which I mentioned) they do not. If there was a caching-related or plugin-related problem I would expect it to impact all fields and now just one or two.

For example, the first snippet works perfectly find when applied to the ‘price’ field, but not for the ‘quantity’ field.

P.S. Why is it that my license code isn’t giving my user avatar the star?

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [August 14, 2024, 11:44am UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/6 "2024-08-14T11:44:18Z")

</div>

Sorry for the confusion. This issue may occur if these fields are not attributes, and they are added as fields on the form level. In this case you have to filter the form instead of attributes so there’s a different hook, for listings it’s `hivepress/v1/models/listing`, then you can change `$listing['fields']` array inside it. You can also check the `hivepress/v1/forms/listing_update` hook.

Hope this helps

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 14, 2024, 12:08pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/7 "2024-08-14T12:08:48Z")

</div>

Hi @ihor , could you please supply me with the full snippet to change the ‘quantity’ field on the Listings page to optional?

P.S. Why is it that my license code isn’t giving my user avatar the star?

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 15, 2024, 1:50pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/11 "2024-08-15T13:50:57Z")

</div>

This works for the ‘price’ field, but not for the ‘quantity’ field.

```auto
add_filter(
    'hivepress/v1/forms/listing_update',
    function( $form ) {
        $form['fields']['quantity']['required'] = false;
        $form['fields']['price']['required'] = false;

        return $form;        
    },
    1000
);

```

Please provide a snippet that works for the ‘quantity’ field.

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [August 16, 2024, 11:57am UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/12 "2024-08-16T11:57:06Z")

</div>

Please try the solution described here [Quantity and purchase note required](https://community.hivepress.io/t/quantity-and-purchase-note-required/8549) We tested it locally and it seems to work. If it doesn’t work make sure that it’s added correctly, you can also disable other HivePress extensions that may conflict with the quantity field just to check, e.g. Bookings if you have it installed. We tested this locally with HivePress and Marketplace only.

Thanks for reporting the support badge issue, I guess there’s something with the payment provider API, I’ll test this further.

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 16, 2024, 1:10pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/13 "2024-08-16T13:10:16Z")

</div>

@ihor this is the first snippet I tried. It doesn’t work. The ‘quantity’ field remains mandatory.

> make sure that it’s added correctly

It’s added like all my other snippets which work. (Plugin: Code Snippets)

> disable other HivePress extensions that may conflict with the quantity field

I also tried with only HivePress and Marketplace activated, and it’s still not working.

 ![Screenshot from 2024-08-16 15-06-55](https://community.hivepress.io/uploads/default/original/2X/b/b8ca4fd9e9cf1a8615353a647c9b64af96055218.png)

Remember, I am trying to make the quantity field **optional** , not mandatory. The snippet you refer to is for making that field mandatory. Have you tested making the field **optional**?

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 19, 2024, 9:35am UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/15 "2024-08-19T09:35:41Z")

</div>

In the meantime I created a new Listing attribute to replace the built-in quantity field, and did not make it mandatory.

So moving on the the second snippet that didn’t work …

```auto
add_filter(
	'hivepress/v1/forms/listing_update',
	function( $form ) {
		$form['fields']['extras']['label'] = 'shipping options';

		return $form;
	},
	1000
);

```

Why doesn’t this work?

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 19, 2024, 12:08pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/17 "2024-08-19T12:08:59Z")

</div>

I have also tried this snippet without success:

```auto
add_filter(
	'hivepress/v1/forms/listing_update',
	function( $form ) {
		if ( isset( $form['fields']['price_extras'] ) ) {
			$form['fields']['price_extras']['label'] = 'shipping options';
		}

		return $form;
	},
);

```

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [August 19, 2024, 1:22pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/18 "2024-08-19T13:22:12Z")

</div>

Hi,

1. Regarding the quantity field, you specified that you need to make it a required field, and now you have indicated that you need to make it optional. Note that this field is optional by default, so you don’t need any additional PHP snippets.

2. Please use this PHP snippet:

```auto
add_filter(
	'hivepress/v1/forms/listing_update',
	function( $form ) {
		if ( isset( $form['fields']['price_extras'] ) ) {
			$form['fields']['price_extras']['label'] = 'shipping options';
		}

		return $form;
	},
1000
);

```

In the previous one, you did not specify “1000”.

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 19, 2024, 1:45pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/19 "2024-08-19T13:45:42Z")

</div>

Hi @andrii ,

1. No I didn’t. You can see in my opening post that the snippet has ‘required’ set to ‘false’. If you are referring to the name of the thread - I created the thread with a different title than the one it has now - someone else changed it!

Furthermore, if I enable the ‘Allow sellers to limit quantity’ option (HivePress → Settings → Listings), the resulting ‘Quantity’ field is not optional:

![Screenshot from 2024-08-19 15-41-56](https://community.hivepress.io/uploads/default/original/2X/8/807015b2c7c98d29e2d4048d962edea40ecbb23d.png)

1. That worked! Thanks!  
Is it possible to limit the selection to only one extra?

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 19, 2024, 1:50pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/20 "2024-08-19T13:50:34Z")

</div>

@andrii it looks like you are the one who edited the thread title … or!? 😁

 ![Screenshot from 2024-08-19 15-49-28](https://community.hivepress.io/uploads/default/original/2X/3/320b1c4bd15d68c1842de8e2a22bcaf5c25262a6.png)

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [August 20, 2024, 1:24pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/23 "2024-08-20T13:24:39Z")

</div>

Hi,

I see. We are changing the titles to make it easier for users to find answers on the forum. Since the quantity field is optional by default, we changed the title, you can check the screenshots for more details:  
[https://www.awesomescreenshot.com/image/50129685?key=6caa60c91afd08116949c7fc90fc70cd](https://www.awesomescreenshot.com/image/50129685?key=6caa60c91afd08116949c7fc90fc70cd)

[https://www.awesomescreenshot.com/image/50129699?key=c977517a0e1fead0a1adc372aed8c878](https://www.awesomescreenshot.com/image/50129699?key=c977517a0e1fead0a1adc372aed8c878)

There is no such feature as limit selection, you would need a custom implementation on the `hivepress/v1/forms/listing_update/errors` hook and check how many extras are trying to be saved and generate an error based on that.

Also, please note that while we try to provide coding-related guidance to help third-party developers and to prevent getting stuck when it comes to customizing our products, unfortunately, we can’t provide specific guidance along with ready-made code snippets; customization is beyond the support scope included with the purchase [Support Policy | HivePress](https://hivepress.io/support-policy/)

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [August 20, 2024, 1:56pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/24 "2024-08-20T13:56:37Z")

</div>

@andrii

1. that is so weird.  
I also have this option enable …  
 ![Screenshot from 2024-08-20 15-51-07](https://community.hivepress.io/uploads/default/original/2X/7/7fcdf39202a1149df37cc15514a49e05663a2163.png)  
… but for me the ‘Quantity’ field is not optional.  
 ![Screenshot from 2024-08-20 15-51-39](https://community.hivepress.io/uploads/default/original/2X/6/6cb9d50598507e898a949009a41f1c7d5cd59bae.png)  
How is that possible?

2. Sorry if I wasn’t clear enough. Currently if the listing includes 3 extras, they appear on the listing as checkboxes, and the customer can select more than one extra.  
I’m looking for a way to make it so that the customer can only select one extra. Maybe changing from checkboxes to radio buttons would do the trick?

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [August 21, 2024, 1:04pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/27 "2024-08-21T13:04:41Z")

</div>

Hi,

1. I see. Please disable third-party plugins and customizations (if there are any) and check if this issue persists. If you use a caching plugin, make sure that caching is disabled for logged-in users. Please note that you need to disable all plugins except for HivePress extensions.

2. Yes, perhaps a radio button will help with this, but it will require a custom implementation using the `hivepress/v1/forms/listing_buy` hook.

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [September 9, 2024, 12:35pm UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/28 "2024-09-09T12:35:52Z")

</div>

Sorry for the delay in replying.

I tested with all plugins disabled other than the HivePress plugins/extensions and WooCommerce, and the ‘Quantity’ field shows up as mandatory:

![image](https://community.hivepress.io/uploads/default/original/2X/d/d55af88fe92e6949c6e2bffcea6fe6cd3eeac595.png)

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [September 10, 2024, 7:47am UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/30 "2024-09-10T07:47:25Z")

</div>

Hi,

Please send temporary WP access to [support@hivepress.io](mailto:support@hivepress.io) with details for reproducing this issue, and we’ll check it (please send only the link, without login and password). You can create a temporary access link using this plugin: [Temporary Login Without Password – WordPress plugin | WordPress.org](https://wordpress.org/plugins/temporary-login-without-password).

---

<div class="post-metadata">

**Author:** ![eab](https://community.hivepress.io/letter_avatar_proxy/v4/letter/e/e47c2d/32.png) [@eab](https://community.hivepress.io/u/eab)\
**Post date:** [September 10, 2024, 8:11am UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/31 "2024-09-10T08:11:33Z")

</div>

Done (Email sent)! ✅

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [September 11, 2024, 7:50am UTC](https://community.hivepress.io/t/make-quantity-field-optional/11782/33 "2024-09-11T07:50:59Z")

</div>

Hi,

We have checked this issue and it is caused by customizations. You had the ListingHive child theme activated, where these customizations were, and when the parent theme is enabled, everything works correctly.

[Next page](https://community.hivepress.io/t/make-quantity-field-optional/11782.md?page=2)
