Additional Order Details on the “View Order” and “Thank You” Pages

In the first post of this series we added our own custom checkout fields, in the second post we customized Order Details metabox in admin area. Today we’ll add order custom fields to user pages: Order Received page and View Order page in My Account.

/5 comments

Below is the example of additional fields on the My Account > Orders > View Order page with active Storefront theme.

Additional order details on the View Order page.

woocommerce_view_order action hook is for the View Order page, woocommerce_thankyou is for the Order Received page. The code for your functions.php below.

<?php
add_action( 'woocommerce_thankyou', 'misha_view_order_and_thankyou_page', 20 );
add_action( 'woocommerce_view_order', 'misha_view_order_and_thankyou_page', 20 );
 
function misha_view_order_and_thankyou_page( $order_id ){  ?>
    <h2>Gift Order</h2>
    <table class="woocommerce-table shop_table gift_info">
        <tbody>
            <tr>
                <th>Is gift?</th>
                <td><?php echo ( $is_gift = get_post_meta( $order_id, 'is_gift', true ) ) ? 'Yes' : 'No'; ?></td>
            </tr>
            <?php if( $is_gift ) : ?>
            <tr>
                <th>Gift Wrap</th>
                <td><?php echo get_post_meta( $order_id, 'gift_wrap', true ); ?></td>
            </tr>
            <tr>
                <th>Recipient name</th>
                <td><?php echo get_post_meta( $order_id, 'gift_name', true ); ?></td>
            </tr>
            <tr>
                <th>Gift message</th>
                <td><?php echo wpautop( get_post_meta( $order_id, 'gift_message', true ) ); ?></td>
            </tr>
            <?php endif; ?>
        </tbody>
    </table>
<?php }

If the order is not marked as a gift, the Gift Wrap, Recipient name and Gift Message fields won’t be displayed.

More about Order Meta

Need some help with WooCommerce?

If you need some professional developer help, I will be happy to assist you.

Contact me Who I am?

Comments — 5

Leave a comment

php js HTML CSS Code