-2

How do I change the delivery date section to automatically update to 3 weeks in the future based on todays date? Right no it just says 2-4 days.

function sv_shipping_method_estimate_label( $label, $method ) {
    $label .= '<br /><small>';
    switch ( $method->method_id ) {

        case 'free_shipping':
            $label .= 'Est delivery: 2-4 days';


    }

    $label .= '</small>';
    return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'sv_shipping_method_estimate_label', 10, 2 );
  • 1
    Possible duplicate of [php date format YYYY-MM-DD minus or add one week from now?](https://stackoverflow.com/questions/6086389/php-date-format-yyyy-mm-dd-minus-or-add-one-week-from-now) – ficuscr Aug 03 '17 at 17:51

1 Answers1

0

You can add a number (e.g., 21 days) to a date by creating a date object using DateTime, and then DateInterval to add the number of days. PHP documentation is here:

http://php.net/manual/en/datetime.add.php

Date format is personal preference, but once the date object is formatted, just concatenate that to the desired label, such as:

$theNewDate = new DateTime(date("Y-m-d"));
$theNewDate->add(new DateInterval('PT1814400S'));
/* I use 1814400 seconds just to demonstrate one way of adding 21 days    */
/* You can just as easily use $theNewDate->add(new DateInterval('P21D')); */

$label .= '<br /><small>';
switch ( $method->method_id ) {

    case 'free_shipping':
        $label .= 'Est delivery date: ';
        $label .= $theNewDate;

}