Change the price format

Hello,

At the moment, my pricing are calculated per guest. The price increase with the number of guest and it’s totally fine.

But for some of my listing, I would like to create a price per group instead of per guest. I want that price to be fixed.

The easiest option to do that is probably to put max number of guest as one but I would like to change the wording of the listing. I would like to replace “guest” by “group”. Can you please explain how to do that for specific listings, not all listings.

I look forward to hear from you.

Please send more details about the issue, if you mean changing the displayed price format (not the price calculation logic) from just “$123” to “$123 / group” for listings, let me know how these listings differ (e.g. by category).

I just want to change the price format. For example, I want to replace “Guests” by “Group” in the listing page.

I want to do this change for some listings only, not all of them. It’s not really for a specific category.

Please let me know how do you differentiate these listings that require group pricing, some category or custom attribute is required to differentiate them, otherwise it’s not possible to check via the code if the listing requires the price format change. Another solution is setting specific listing IDs in the code, would this work for you?

Hello @ihor , thank you for your reply. Ok I understand your comment. I can set up custom attribute like this:

Private: Yes or No

if Yes => replace “guests” by “group”.

if No => no replacement.

Is it possible like that?

Thank you for waiting. Please try this PHP code snippet. Please change hp_listing_put_here_attribute_field_name on hp_listing_ + field name of the listing attribute you will use for this condition. Also, please change Put the name of option here on the name of option, which allows to change the guest by group in the price field. For example, if you have two options, “Yes” and “No” in the attribute, then please put “Yes” here.

add_filter(
	'hivepress/v1/models/listing/fields',
	function( $fields, $model ) {
		if(!isset($fields['price']) || !has_term('Put the name of option here', 'hp_listing_put_here_attribute_field_name', $model->get_id())){
			return $fields;
		}
		
		$fields['price']['display_template'] = '%value% / group';
		return $fields;
	},
	2000,
	2
);

Hello,

I used the code that you mentioned but it didn’t work.

add_filter(
	'hivepress/v1/models/listing/fields',
	function( $fields, $model ) {
		if(!isset($fields['price']) || !has_term('yes', 'hp_listing_group_pricing', $model->get_id())){
			return $fields;
		}
		
		$fields['price']['display_template'] = '%value% / group';
		return $fields;
	},
	2000,
	2
);

Can you give me an alternative?

Thank you!

Please try the code snippet without this part.

if(!isset($fields['price']) || !has_term('yes', 'hp_listing_group_pricing', $model->get_id())){
	return $fields;
}

If it works without this condition, then please make sure that condition is correct.

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