Adding days to date string

I’m using WooCommerce Invoice PDF plugin which is a plugin for an e-shop within WordPress.

The invoice plugin does not have any “due date” function so I tried to create one myself.

Read More
<?php echo $this->get_woocommerce_pdf_date ( $order_id,'ordered' ) ; ?>

Here is the string which gathers the information from the order. It collects and displays the day the order was placed. I would like to add + 20 days to that string but haven’t been able.

I have very little knowledge on PHP so I would REALLY appriciate any help at all.

Related posts

Leave a Reply

1 comment

  1. You’ll want to use PHP’s DateTime class. You can construct the object with any date string, I used 2014-01-15 in my example. Then you can ::modify() it and get the string by using ::format(). Check the documentation for other formats, but I used Y-m-d.

    <?php
    $date_string = '2014-01-15';
    $date = new DateTime($date_string);
    $date->modify('+20 days');
    $date_string = $date->format('Y-m-d');
    
    var_dump($date_string);
    // string(10) "2014-02-04"
    ?>
    

    If you get your date’s string with the get_woocommerce_pdf_date() function, you can integrate this like so:

    <?php
    $date = new DateTime($this->get_woocommerce_pdf_date($order_id,'ordered'));
    // Modify and format the date object to your liking.