Snippet for Non Editable Default Listing Attribute

Hello, for regular listings:

I have an attribute field name compras_protegidas

type: select - I edit the options and created the one I want to be default.

the default selection should be the one with ID=269

I am using this code bellow without success, basically it is the same snippet I used for default vendors attribute, I just changed the vendor for listing, but didnt work.

Should I change something else? Is there a mistake? Thanks

add_action(
	'hivepress/v1/models/listing/create',
	function ($listing_id, $listing){
		$listing->set_compras_protegidas(269)->save_compras_protegidas();
	},
	1000,
	2
);```

Please make sure that the option ID exists in attribute options and please make sure that the correct field name is used in the code snippet

Please copy this PHP snippet. It seems like there are extra quotes in the code

add_action(
	'hivepress/v1/models/listing/create',
	function ($listing_id, $listing){
		$listing->set_compras_protegidas(269)->save_compras_protegidas();
	},
	1000,
	2
);

Hi @yevhen unfortunately it doesnt work, keeps unchecked in the system. I have both marketplace and bookings installed.

The attribute is not for all categories. Should it be definied wich category should go?

Thanks

Please try this PHP snippet instead

add_action(
	'hivepress/v1/models/listing/update_categories',
	function ($listing_id, $value){
		$listing = HivePress\Models\Listing::query()->get_by_id($listing_id);
		
		if(!$listing){
			return;
		}
		
		$listing->set_compras_protegidas(269)->save_compras_protegidas();
	},
	1000,
	2
);
1 Like