I'm trying to generate a series of shortcodes which return a) a product lead time in days, and b) the expected dispatch date, based on this lead time.
The idea is that the lead times can be set in one place, and the shortcodes embedded on various pages are automatically updated with the lead time and dispatch dates.
I've put the following together for two categories (prepours and ready pours), but am not having much luck as yet.
Any help would be much appreciated!
function add_days( $days, $from_date = null ) {
if ( is_numeric( $from_date ) ) {
$new_date = $from_date;
} else {
$new_date = time();
}
// Timestamp is the number of seconds since an event in the past
// To increate the value by one day we have to add 86400 seconds to the value
// 86400 = 24h * 60m * 60s
$new_date += $days * 86400;
return $new_date;
}
// Define Current Lead Times Here
$prepour_lead_time = 10 ;
$ready_pour_lead_time = 3 ;
//
$prepour_ship_date = add_days( $prepour_lead_time );
$ready_pour_ship_date = add_days( $ready_pour_lead_time );
// Lead Time Shortcodes
function prepour_lead_time_function() {
return ( $prepour_lead_time );
}
add_shortcode('prepour_lt', 'prepour_lead_time_function');
function ready_pour_lead_time_function() {
return ( $ready_pour_lead_time );
}
add_shortcode('readypour_lt', 'ready_pour_lead_time_function');
// Shipping Date Shortcodes
function prepour_ship_date_function() {
return ( $prepour_ship_date );
}
add_shortcode('prepour_sd', 'prepour_ship_date_function');
function ready_pour_ship_date_function() {
return ( $ready_pour_ship_date );
}
add_shortcode('readypour_sd', 'ready_pour_ship_date_function');
source https://stackoverflow.com/questions/68565893/wordpress-shortcode-date-based-on-global-product-lead-time
Comments
Post a Comment