Hello,
I have a custom post type with these 2 custom fields :
ORDERDATE = date of the order
DAYS = number of days
Based on those, I need to calculate a deadline, that will display in views : DEADLINE = ORDERDATE + DAYS.
I wonder what shortcode I should use (and possibly customize) to make it work.
Thank you.
Dear roman,
There isn't such a existed shortcode works for your case,
I suggest you create another new shortcode for it:
https://codex.wordpress.org/Function_Reference/add_shortcode
1) Get the values of custom field "ORDERDATE" and "DAYS"
https://codex.wordpress.org/Function_Reference/get_post_meta
2) Calculate the value as what you want:
DEADLINE = ORDERDATE + DAYS.
Thank you, here it is if anyone needs it :
/**************************************************
* Shortcode pour calculer le délai effectif de livraison d'une commande
**************************************************/
function calculer_delaireel_de_livraison( ) {
$post_id = get_the_ID();
$date_commande = get_post_meta($post_id,'wpcf-date-de-la-contractualisation-de-la-commande', true);
$date_livraison = get_post_meta($post_id,'wpcf-date-de-livraison-de-la-commande', true);
$delaireel = ($date_livraison - $date_commande)/(60 * 60 * 24);
if ($delaireel < 1) {
return "le jour même" ;
}
elseif ($delaireel < 2) {
return "en " . round($delaireel) . " jour" ;
}
else {
return "en " . round($delaireel) . " jours" ;
}
}
add_shortcode( 'delai-reel', 'calculer_delaireel_de_livraison' );