How to calculate price based on a custom attribute value

I would like to set the value of a listing’s ‘Price’ based on the value inputted by a user for ‘Displayed Hourly Rate’ (displayed_hourly_rate).

I’ve tried the following code with no success, based on this post: Calculated Attributes

add_action(
	'hivepress/v1/models/listing/update',
	function( $listing_id, $listing ) {
		$value = $listing->get_displayed_hourly_rate() * 1.1;

		if ( $listing->get_price() !== $value ) {
			$listing->set_price( $value )->save_price();
		}
	},
	1000,
	2
);

The code snippet seems to be ok, please try debugging this using error_log, checking variables and conditions. If it’s a custom attribute, there may be an easier way if you just rename the Price field to Hourly Rate, if there’s no other reason for syncing Price with another attribute.

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