Default value for attributes

I wonder if can set a default value for an attribute field?
I know the placeholder field, but if the user starts writing in the field, the placeholder disappears (which is the correct behavior).

I want to make a “WhatsApp” attribute, which has the default WhatsApp address “https://wa.me/” as Value, so the User only have to add his number at the end.

The same with the “Homepage” attribute and “https://” as default value.

I allready tried to use some snippets, but it didn’t work out.

add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset( $attributes['whatsapp'] ) ) {
			$attributes['whatsapp']['edit_field']['value'] = "Test";
			$attributes['whatsapp']['edit_field']['_value'] = "Test";
			$attributes['whatsapp']['edit_field']['placeholder'] = "Test";
		}

		return $attributes;
	},
	1000
);

Please try to change ['value'] and ['_value'] to ['default']

Thank you for the idea. Unfortunately, this wasn’t the solution.
I also tried “default-value” but it didn’t work.

Any other suggestions?

Please try this PHP snippet instead. It will add default value for new listings

add_action('hivepress/v1/models/listing/create', function($listing_id) {
	update_post_meta($listing_id, 'hp_whatsapp', 'Test');
});

Works like a charm :slight_smile:

Thank you very much.

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