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!!
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
Thx Waqar!!
It seems to work - If I set the conditional to "yes" it shows, if to "no" it doesn't.
Great help!!!
Ido