1
votes

I am having some issues with this code. I just want to display an Order Date + 5 Days on my thank you page for the estimated delivery time.

// The orders date
$order_date = $order->get_date_created();
$order_date = $order_date->date('Y-m-d H:i:s');

// The order date + 5 days
$order_date_5d = date( 'Y-m-d H:i:s', strtotime( $order_date . ' +5 days' );

// TESTING OUTPUT
echo 'ORDER DATE: ' . $order_date . '<br>';
echo 'ORDER DATE + 5 days: '.$order_date_5d . '<br>';

For some reason I am not being able to make this a simple shortcode. Any ideas or suggestions to make this work?

Thank you! Jessica <3

1
There is an error in your code. You forgot to close ) to here date( 'Y-m-d H:i:s', strtotime( $order_date . ' +5 days' ); - Bhautik

1 Answers

0
votes

Check here http://sandbox.onlinephpfunctions.com/code/b180cebbbb0b94226e21202b15c70292c1215a0c

function show_date( $atts ){

    $atts = shortcode_atts( array(
        'order_id' => '',
        '' => ''
    ), $atts, 'show_date' );

    $order = wc_get_order( $atts['order_id'] );

    // The orders date
    $order_date = $order->get_date_created();
    $order_date = $order_date->date('Y-m-d H:i:s');

    // The order date + 5 days
    $order_date_5d = date( 'Y-m-d H:i:s', strtotime( $order_date . ' +5 days' ) );

    // TESTING OUTPUT
    $html = 'ORDER DATE: ' . $order_date . '<br>';
    $html .= 'ORDER DATE + 5 days: '.$order_date_5d . '<br>';

    return $html;
}
add_shortcode( 'show_date', 'show_date' );

USE

[show_date order_id="yourorder-id"];