简体   繁体   中英

How to Add Order Number, Order Date and Hour in a Woocommerce Email Template

I've been struggling for more than 4 days to customize my small WooCommerce shop email template by wanting to add the following requisites - order number, order date and hour when the order was mode.

This is the email template:

<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/*
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_formatted_billing_full_name() ) ); ?></p>
<p><?php esc_html_e( 'Your order №X from date X hour X was processed. You can track the delivery progress by clicking on the shipping number:', 'woocommerce' ); ?></p>

<blockquote><?php echo wpautop( wptexturize( make_clickable( $customer_note ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></blockquote>


<?php

/**
 * Show user-defined additional content - this is set in each email's settings.
 */
if ( $additional_content ) {
    echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
}

/*
 * @hooked WC_Emails::email_footer() Output the email footer
 */
do_action( 'woocommerce_email_footer', $email );

You may get values for your needs by following functions

// Get Order ID/Number
$order->get_id();

For Order Dates here are the multiple function with different dates you may use them

// Get Order Dates
$order->get_date_created();  //Order Created Date
$order->get_date_modified(); //Order Modified Date
$order->get_date_completed();//Order Completed Date
$order->get_date_paid();     //Order Paid Date

I hope this helps you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM