Vendor Attribute With Default Option

I want to show right from the start that a vendor is not Verified yet, so I created the non editable on the interface attribute

“Verification” (field name verificacao) with 2 options:

  1. Verified
  2. Pending Verification

Right now after the vendor creates his first service, I must check manually that the Verification is Pending.

Is there a way to make so that the vendor has the attribute already with the option Pending Verification so I only need to change it manually after the vendor verifies his profile?

This should work,
your_field_name is your field name you previously set,
value is the value you want it to be, (bool, string, int).

add_filter(
	'hivepress/v1/meta_boxes/vendor_attributes',
	function($args){
		if(isset($args['fields']['your_field_name'])){
			$args['fields']['your_field_name']['default'] = value;	
		}
		
		return $args;
	},
	1000
);
1 Like

Hi Stefan,

it produced a fatal error on the website… the message is:

Parse error: syntax error, unexpected ‘Pendente’ (T_STRING) in C:\Users\COMPRAS PROTEGIDAS\Local Sites\banco-de-palestrantes\app\public\wp-content\plugins\code-snippets\php\snippet-ops.php(484) : eval()'d code on line 5

this is the code I used:

add_filter(
	'hivepress/v1/meta_boxes/vendor_attributes',
	function($args){
		if(isset($args['fields']['verificacao'])){
			$args['fields']['verificacao']['default'] = Verificação Pendente;	
		}
		
		return $args;
	},
	1000
);

The reason why this caused a fatal error is because the value cannot be just simple text.
It needs to be a data type, like a bool (true, false), int (number: 1, 2, 3), string(“verified”).
It depends on what kind of field type you are using (Number, Phone, Checkbox, Select etc…)

Try this.

add_filter(
	'hivepress/v1/meta_boxes/vendor_attributes',
	function($args){
		if(isset($args['fields']['verificacao'])){
			$args['fields']['verificacao']['default'] = 'Verificação Pendente';	
		}
		
		return $args;
	},
	1000
);

Thank you Stefan, I tried this new one but nothing shows on new registered vendors…keeps empty

From the first code you proposed me, I understand now I should have used “true” as a value, right? Also I should have created only one option for the attribute (before I had 2 options, pending and verified)

Should the attribute be a select type, non editable on front end, with only one option? I would like to all new vendors have the icon and the text “Verificação Pendente”, just like the image attached.

%icon% %value% position block secundary and page secundary,
Screenshot_69

thank you again!

Hello,

anyone knows the answer?

how to make a default attribute option non editable on front end so that it already appears after vendor creates first listing?

For example, for the attribute Verification I have 2 options: Pending and Verified. I created it as a select type attribute.

The attribute with its 2 options is filterable.

I would like for the %icon% %value% , in this case the value Pending, to be automatically assigned to all vendors on the block secondary position, and page secondary position.

So only after the vendor verifies his profile, I will change manually to the option Verified. Otherwise the %icon% Pending will be shown as default.

Is this possible?

Thank you

Hey, I think you can solve your problem by looking at my thread.
Hope it helps.

Thank you Stefan, I will give it a try. I am a little confused because there is an icon and also the attribute has two options. Will make some testes! :slight_smile:

The suggested code snippet should be ok, but please note that there’s the same icon per attribute, not per each attribute option - this would require further customizations.

Hello Yevhen,

unfortunately it doesnt work for me… I added this code snippets:

FIRST, I ADDED

add_filter(
	'hivepress/v1/meta_boxes/vendor_attributes',
	function($args){
		if(isset($args['fields']['verificacao'])){
			$args['fields']['verificacao']['default'] = 'Verificação Pendente';	
		}
		
		return $args;
	},
	1000
);

Nothing was changing on the profile for new vendors, so I followed Stefan suggestion and read his other thread where maybe the problem is that it is not saving the information when vendor creates account from the front end.

So I tried adding this snippet:

add_action(
	'hivepress/v1/models/vendor/create',
	function ($vendor_id, $vendor){
		$vendor->set_verificacao('Verificação Pendente')->save_verificacao();
	},
	1000,
	2
);

still no result… :slightly_frowning_face:

If it’s a Select attribute, please use the option ID instead of label in this code snippet:

add_action(
	'hivepress/v1/models/vendor/create',
	function ($vendor_id, $vendor){
		$vendor->set_verificacao(123)->save_verificacao();
	},
	1000,
	2
);

Please replace 123 with the option ID (you can check it in the browser address bar while you edit the ‘Verificação Pendente’ option, it looks like “…tag=123…”).

1 Like

Hello @ihor can this code be used also for default attribute for listings? should I cnage only the “vendor” for “listing” ?

Thanks

Yes, changing all the “vendor” occurrences with “listing” should work.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.