Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

php - Add created date timestamp to WooCommerce customer emails

I'm trying to add order time next to the date on the Thank you screen and in the default Processing order email to the customer. Currently, it looks as follows:

Thank you page: https://i.stack.imgur.com/f0v6Y.png

Processing order email: https://i.stack.imgur.com/NwaU0.png

I've tried messing around with original files on the lines mentioned here below, e.g. $order->get_date_created("d-m-Y, H:i") but without any success.

email-order-details.php line 34:

    echo wp_kses_post( $before . sprintf( __( '[Order #%s]', 'woocommerce' ) . $after . ' (<time datetime="%s">%s</time>)', $order->get_order_number(), $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ) );

and thankyou.php line 51-54:

            <li class="woocommerce-order-overview__date date">
                <?php esc_html_e( 'Date:', 'woocommerce' ); ?>
                <strong><?php echo wc_format_datetime( $order->get_date_created() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
            </li>

Here they were able to add the time on a separate row in the emails, with editing the functions.php file. The only difference with my question is, they added the date and time on a separate row, so now you have 2 lines with dates. And this doesn't work on "Thank you" page.

Can you help me with similar kind of code (so code to add in the functions.php file) but more precise to my question? Thanks

question from:https://stackoverflow.com/questions/65941288/add-created-date-timestamp-to-woocommerce-customer-emails

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<?php echo date( 'Y F j, g:i a', $order->get_date_created ()->getOffsetTimestamp()); ?>

enter image description here

<?php echo wp_kses_post( $before . sprintf( __( '[Order #%s]', 'woocommerce' ) . $after . ' (<time datetime="%s">%s</time>)', $order->get_order_number(), date( 'Y F j, g:i a', $order->get_date_created ()->getOffsetTimestamp()), date( 'Y F j, g:i a', $order->get_date_created ()->getOffsetTimestamp()) ) ); ?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...