Listing Expiration via Attribute and Todays Date

Hi there,

I’ve seen a few posts about the listing expiration. I am using listings as event listings so have a event start date which is search-able and filterable. My concern is website showing listing that happened in the past. So I’ve added event end date which can double up as expiration date. Is there a simple way to auto hide or expire listings where the date is more than 1 or 2 days past today?

Attributes:

  • Start Date
  • End Date

System Attribute?

  • Current Date

Also is there an option to not send email about listing expirations as it’s implied that after the event date, it makes sense that the listing retires.

Thanks in advanced

Please clarify do you mean that the listing should expire in 2 days after the date which is set in the custom End Date attribute, am I correctly understand you?

1 Like

Yes, that would be perfect. I mean it should expire as soon as event is over as you can not attend it so displaying it would not provide value but was playing with the idea if having it display for 1 or 2 more days to show what’s been happening.

But would play with the idea on which way to go.

Thanks

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

Thank you, currently testing this.

Is it better to “Run snippet everywhere” or just " Only run on site front-end", I am unsure if this is a front end or back end filter but assume the other options of Admin area and One Time won’t suit my needs.

In this case, it is better to run the snippet everywhere

1 Like

Thank you, tested this and it’s working like a dream :slight_smile:

Is there any way to toggle emails being sent when it expires? At the moment the function is fine but thinking if people get annoyed with frequency of emails then I can consider turning off the email notification as an option. Ideally the user should be able to unsubscribe to Listing Expiration as an individual option i.e. not block all email comms (as they’d need password resets etc.)

If you want to stop sending emails when the listing expires, then please try to create an empty email template in HivePress/Emails for the Listing Expired event

1 Like

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