2017-08-03 70 views
-2

如何根據今天的日期將交貨日期部分更改爲將來3周自動更新?對不,它只是說2-4天。簡單日期php更改

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

[PHP的可能的複製日期格式YYYY-MM-DD減去或添加一週後?](https://stackoverflow.com/questions/6086389/php-date-format-yyyy-mm-dd-minus-or-add-one-week -現在起) – ficuscr

回答

0

可以通過創建使用日期時間的日期對象的數(例如,21天)添加到一個日期,然後DateInterval添加的天數。 PHP文件是在這裏:

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

日期格式是個人喜好,但一旦日期對象的格式,只是串聯,爲所需的標籤,如:

$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; 

}