Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 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 Reply

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()) ) ); ?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...