Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce Custom Field on Custom Order Details Page

Looking over the docs, there does not appear to be a clear way to display a custom field on the customer's order details page. I have no problem getting my custom fields to display on the admin order details or the customer's email.

The only way I can see that it can be done is if by copying over the "woocommerce/order/order-details.php" in the theme's folder. This is undesirable as it requires me to have a lingering template file that may or may not need to be updated if woo developers change the original.

Is there a filter that can allow me to add the custom field to the customer's order details page without relying on a template?

Just to clarify, the page I am looking to add this is when the user completes the order (their receipt page).

Many thanks!

like image 574
joeyd Avatar asked Dec 07 '22 02:12

joeyd


1 Answers

Resolved. I missed this function in the docs.... "woocommerce_order_details_after_order_table".

This function will add your custom fields to the order details page. In my case...

add_action( 'woocommerce_order_details_after_order_table', 'nolo_custom_field_display_cust_order_meta', 10, 1 );

function nolo_custom_field_display_cust_order_meta($order){
    echo '<p><strong>'.__('Pickup Location').':</strong> ' . get_post_meta( $order->id, 'Pickup Location', true ). '</p>';
    echo '<p><strong>'.__('Pickup Date').':</strong> ' . get_post_meta( $order->id, 'Pickup Date', true ). '</p>';
}
like image 156
joeyd Avatar answered Dec 23 '22 20:12

joeyd