Skip Navigation

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

This support ticket is created hace 5 años, 3 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por Ido Angel hace 5 años, 3 meses.

Asistido por: Waqar.

Autor
Mensajes
#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

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