Listing Expiration via Attribute and Todays Date

Please try this PHP snippet. Please change attribute_field_name on the attribute field name

add_action(
	'hivepress/v1/models/listing/update',
	'custom_update_expiration_date',
	10,
	2
);

function custom_update_expiration_date($listing_id){
	remove_action( 'hivepress/v1/models/listing/update', 'custom_update_expiration_date', 10, 2 );
	
	$listing = \HivePress\Models\Listing::query()->get_by_id($listing_id);
	
	if(!$listing){
		return;
	}
	
	$end_time = $listing->get_attribute_field_name();
		
	if(!$end_time){
		return;
	}
		
	$listing->set_expired_time(strtotime('+2 days', strtotime($end_time)))->save_expired_time();
}
3 Likes