Skip Navigation

[Résolu] show field only if a year HASN'T passed from a date within another field

This support ticket is created Il y a 4 années et 8 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Karachi (GMT+05:00)

This topic contains 2 réponses, has 2 voix.

Last updated by Ido Angel Il y a 4 années et 8 mois.

Assisted by: Waqar.

Auteur
Publications
#1326777

Hey,

Whenever a client created an order in a cred form, there's a text field which I have populated with today's date, using:

add_shortcode('wpv-post-today', 'today_shortcode');
function today_shortcode() {
return date( 'd/m/Y', current_time( 'timestamp' ));
}

I have a view showing all orders, and in this view there's an "edit order" button for, well, editing the order 🙂
I need this button to be available only if:
1) there "today's date" text field isn't empty
AND
3) a year HASN'T passed after the order has been placed

What's the conditional I need to use for the editing button?

For the first condition, I'm using:

[wpv-conditional if="( $(wpcf-closing-order-date) ne '' )"][toolset-edit-post-link layout_slug='edit-order' target='self']<i class="far fa-edit"></i>[/toolset-edit-post-link][/wpv-conditional]

But what other conditional do I need to add for keeping this visible throughout a year after the order has been placed?

thx!!

#1327161

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Ido,

Thank you for waiting.

You can use a single custom shortcode, that checks for both your conditions and returns "yes" or "no" accordingly.

Example:


add_shortcode('show_edit_button', 'show_edit_button_func');
function show_edit_button_func() {

	$format = "d/m/Y";

	$dateOrder = do_shortcode("[types field='closing-order-date'][/types]");

	if(!empty($dateOrder)) {

		$dateToday = date( 'd/m/Y', current_time( 'timestamp' ));

		$dateTodayObj = DateTime::createFromFormat($format, $dateToday);

		$dateOrderObj = DateTime::createFromFormat($format, $dateOrder);

		$diff = date_diff($dateOrderObj,$dateTodayObj);

		if ( $diff->y <= 0 )
		{
			return 'yes';
		}
		else
		{
			return 'no';
		}
	}
	else
	{
		return 'no';
	}

}

Note: Feel free to adjust the shortcode as needed and also add "show_edit_button" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

After that, you'll be able to use it in the conditional code block, like this:


[wpv-conditional if="( '[show_edit_button]' eq 'yes' )"] 
Show Button!!!
[/wpv-conditional]

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1327323

Thx Waqar!!
It seems to work - If I set the conditional to "yes" it shows, if to "no" it doesn't.
Great help!!!
Ido

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.