How to add custom column in shipments table?
- To add header title, copy following code. Change your_function_name to the function name of your choice and “Date Created” to your desired column name.
add_action('wpcfe_shipment_table_header', 'wpcfe_shipment_table_header_callback'); function wpcfe_shipment_table_header_callback(){ echo "<th>Date Created</th>"; }
- To add column data, copy following code. Change your_function_name to the function name of your choice.
add_action("wpcfe_shipment_table_data", "wpcfe_shipment_table_data_callback"); function wpcfe_shipment_table_data_callback( $shipment_id ){ $data = "<td>"; $data .= get_the_date( "Y-m-d", $shipment_id ); $data .= "</td>"; echo $data; }
- To add multiple columns, copy following codes.
add_action("wpcfe_shipment_table_header", "wpcfe_shipment_table_header_callback"); function wpcfe_shipment_table_header_callback(){ echo "<th>Date Created</th>"; echo "<th>Pickup by</th>"; echo "<th>Custom Meta</th>"; } add_action("wpcfe_shipment_table_data", "wpcfe_shipment_table_data_callback"); function wpcfe_shipment_table_data_callback( $shipment_id ){ $data = "<td>"; $data .= get_the_date( $shipment_id, 'Y-m-d' ); $data .= "</td>"; //Another data $data = "<td>"; $data .= get_user_meta( get_current_user_id(), 'first_name', true ); $data .= "</td>"; //Custom data $data = "<td>"; $data .= get_post_meta( $shipment_id, 'custom_meta', true ); $data .= "</td>"; echo $data; }
Need additional code example? click this documentation How to add Employee, Client and other WPCargo user role in shipment table