Code

Add Custom Fields to Order Details Page – WooCommerce WordPress Problem Solution

Add Custom Fields to Order Details Page

sometimes few filed needed when delivery complete or status change of a order. Like shipment date or others info which need a customer to know. Like:

Order Page custom field

order-page-custom-wordpress

Show in Order page

So need a custom hook in theme function.php file. Add this code last portion to the file. That’s it.

Code Part:

/**
 * Add Fields Inside “Order Details” Table
 *
 * @author Hriday Ahmed
 * @link https://dhakato.com/
 */
add_action( ‘woocommerce_order_details_after_order_table_items’, ‘hriday_order_details’ );
function hriday_order_details( $order ) {
//$download = get_post_meta( $order->get_id(), ‘download’, false );
//$shippingdate = get_post_meta( $order->get_id(), ‘shippingdate’, true );
$download = $order->get_meta( ‘download’ );
$shippingdate = $order->get_meta( ‘shippingdate’ );
if( $download ) :
?>
<tr>
<th scope=”row”>Download:</th>
<td><?php echo esc_html( $download ) ?></td>
</tr>
<?php
endif;
if( $shippingdate ) :
?>
<tr>
<th scope=”row”>Shipping date:</th>
<td>
<?php //echo date( ‘F jS, Y’, strtotime( $shippingdate ) ) ?>
<?php //echo esc_html( $order->meta_data->key[‘download’] ) ?>
<?php echo $shippingdate; ?>
</td>
</tr>
<?php
endif;
}
//code end
For more show in youtube: https://youtu.be/zkqxO6kRUiM

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close
Close
Khejur Gur