Skip Navigation

[Resolved] Best Way of Setting Up Posts with Expiry Dates

This support ticket is created 7 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by julieP 7 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#578760

I'm working on a development site. The site contains Listings. Listings are free for 12 weeks. At the end of the 12 weeks, if the user doesn't pay for a full 12 months, the Listing status changes to Draft. The User is sent a reminder 2 weeks before expiry.

Form A is used to create a Listing and sets the Listing to expire after 12 weeks. If the User wants to renew, they are directed to Form B (edit content type) which sets the Listing to expire after 52 weeks (thereby renewing the Listing). At the end of the 52 weeks, they use the same form again to renew for another 52 weeks and so on.

When the User submits Form B, I need two things to happen:-

1. the value of a checkbox needs to change to a different value in the same list.
2. the new expiry date needs to be 52 weeks from the previous expiry date

I've set up this CRED hook to solve point 1:-

add_action('cred_save_data', 'save_data_form_5315',10,2);
function save_data_form_5315($post_id, $form_data)
{
    // This is the Listing_Renew form ID
    if ($form_data['id']==5315)
    {
	
    update_post_meta($post_id, 'wpcf-listing-type', 'Paid');
   } 
}

Where point 2 is concerned, the new expiry date is calculated on the date of publication but the User might renew the Listing up to 2 weeks before the 12 weeks is up and so they lose out. The new expiry date needs to be 52 weeks from the post's previous expiry date so they always get the full period allowed. How do I achieve this please?

#578901

Dear Julie,

Thanks for the feedback, yes you are right, it is expected result:
the new expiry date is calculated on the date of publication
And there isn't such a built-in feature within current CRED plugin that can achieve what you want:
the new expiry date needs to be 52 weeks from the previous expiry date.

If you agree, we can take it as a feature request, our developers will take care of it.

#578902

Hi Luo

Thank you for confirming the behaviour is intended and not a bug.

Yes, please put it forward as a feature request.

In the meantime, can you suggest/work with me on a work around please?

#578946

Here is a workaround you can try:
1) Edit the CRED plugin file \plugins\cred-frontend-editor\library\toolset\cred\embedded\classes\CredPostExpiration.php, add a filter in it, modify line 299~300, from:

					// calculate expiration time and get the corresponding timestamp
					$expire_time = strtotime( '+' . $expiration_amount . ' ' . $expiration_period );

To:

					// calculate expiration time and get the corresponding timestamp
					$expire_time = strtotime( '+' . $expiration_amount . ' ' . $expiration_period );
					$expire_time = apply_filters('custom_expire_time', $expire_time, $post_id, $form_data['id']);

2) Add below codes in your theme/functions.php:

add_filter('custom_expire_time', 'my_func3', 999, 3);
function my_func3($expire_time, $post_id, $form_id){
	if($form_id == 123){
		$oringinal_expire_time = get_post_meta($post_id, '_cred_post_expiration_time', true);
		$time_stamp = time();
		if($oringinal_expire_time > $time_stamp){ // this post is not expired
			$expire_time = $oringinal_expire_time + 365 * 24 * 60 * 60; // extend 1 year(365 days)
		}
	}
	return $expire_time;
}

Please replace 123 with your CRED form ID.

#579397

Hi Luo

That looks like a really neat solution - thank you so much!

I might not get a chance to try it out straightaway so I'm closing this thread for now but will re-open it if I have any problems implementing it.

Really appreciate your help, thank you.