Skip Navigation

[Gelöst] Condition with a date function

This support ticket is created vor 2 Jahre, 9 Monate. 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.

This topic contains 2 Antworten, has 2 Stimmen.

Last updated by Pat vor 2 Jahre, 8 Monate.

Author
Artikel
#2129657

Pat

Hello,

I need to allow the ADD TO CART button on the product page only between 2 specific dates.
For this, I have created 2 custom fields (wpcf-date-debut-inscription-site and wpcf-date-fin-inscription-site) enabling date and time.
These custom fields are linked to a specific postype (variables) and I have created a post (ID 18207) in order to define these dates.
I have also created 2 hooks :

function date_debut_ins( ) {
$id_va = 18207;
$datedebut = get_post_meta($id_va, 'wpcf-date-debut-inscription-site', true );
return $datedebut;
}
  add_shortcode( 'date-debut-ins', 'date_debut_ins' );
function date_fin_ins( ) {
$id_va = 18207;
$datefin = get_post_meta($id_va, 'wpcf-date-fin-inscription-site', true );
return $datefin;
}
  add_shortcode( 'date-debut-ins', 'date_fin_ins' );

and have declareded these function in the Toolset frontend parameter.
Now, I want to define the output condition like this :

[wpv-conditional if="( date_debut_ins() lte 'SECONDS_FROM_NOW(0)' ) AND ( date_fin_ins() gt 'SECONDS_FROM_NOW(0)' )"] [wpv-woo-buy-options]
[/wpv-conditional]

but it seems that the result of the function is a strtotime date number and I don't how what is needed for the condition output in this case.

Can you help please?
Regards
Pat

#2129813

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+01:00)

Hi Pat

First, an observation.

You have registered the function date_debug_ins as a callback for a shortcode, but you don't use the shortcode inside your condition, you use the function directly, so declaring the shortcode seems redundant.

If these fields are Types date fields then, yes, they are stored as timestamps (number of seconds since 1 Jan 1970).

In your condition you are comparing them to SECONDS_FROM_NOW(0). I'm not entirely sure what this is, or what format it returns, but in any case if your intention is to compare them to the current date/time then you can simply use the native PHP function time(), which will return the current date/time as a timestamp (i.e. the same format that Types date fields are stored in).

hidden link

#2130731

Pat

Hi Nigel,

As I already had a shortcode ([post-today]) giving the current date / time in a strotime format, I have modified my condition like this :

[wpv-conditional if="( date_debut_ins() lte [post-today] ) AND ( date_fin_ins() gt [post-today] )"] [wpv-woo-buy-options] [/wpv-conditional]

Everything is fine now.
Thanks
Pat

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