Front-end: How to manipulate shipment table columns
Note: To remove column by user role.
WPCargo Roles
- wpcargo_client
- wpcargo_pending_client
- wpcargo_employee
- cargo_agent
Example
$current_user = wp_get_current_user(); if( in_array( "wpcargo_client", $current_user->roles ) ){ // Remove View Shipment Column remove_action( 'wpcfe_shipment_table_header', 'wpcfe_shipment_table_header_view', 25 ); remove_action( 'wpcfe_shipment_table_data','wpcfe_shipment_table_data_view', 25 ); }
Codes to remove shipment columns
function wpcargo_manipulate_shipment_column_table_callback(){ // Remove View Shipment Column remove_action( 'wpcfe_shipment_table_header', 'wpcfe_shipment_table_header_view', 25 ); remove_action( 'wpcfe_shipment_table_data','wpcfe_shipment_table_data_view', 25 ); // Remove Shipment Type Column remove_action( 'wpcfe_shipment_table_header', 'wpcfe_shipment_table_header_type', 25 ); remove_action( 'wpcfe_shipment_table_data', 'wpcfe_shipment_table_data_type', 25 ); // Remove Shipper / Receiver Column remove_action( 'wpcfe_shipment_after_tracking_number_header', 'wpcfe_shipper_receiver_shipment_header_callback', 25 ); remove_action( 'wpcfe_shipment_after_tracking_number_data', 'wpcfe_shipper_receiver_shipment_data_callback', 25 ); // Remove Status Column remove_action( 'wpcfe_shipment_table_header', 'wpcfe_shipment_table_header_status', 25 ); remove_action( 'wpcfe_shipment_table_data', 'wpcfe_shipment_table_data_status', 25 ); // Remove Shipment Print Column remove_action( 'wpcfe_shipment_table_header_action', 'wpcfe_shipment_table_header_action_print', 25 ); remove_action( 'wpcfe_shipment_table_data_action', 'wpcfe_shipment_table_action_print', 25 ); // Remove Update Shipment Column remove_action( 'wpcfe_shipment_table_header_action', 'wpcfe_shipment_table_header_action_update', 25 ); remove_action( 'wpcfe_shipment_table_data_action', 'wpcfe_shipment_table_action_update', 25 ); // Remove Shipment Delete Column remove_action( 'wpcfe_shipment_table_header_action', 'wpcfe_shipment_table_header_action_delete', 25 ); remove_action( 'wpcfe_shipment_table_data_action', 'wpcfe_shipment_table_action_delete', 25 ); // Remove Est. Charge Column remove_action( 'wpcfe_shipment_table_header', 'wpcpq_shipment_table_header_est_charge', 26 ); remove_action( 'wpcfe_shipment_table_data', 'wpcpq_shipment_table_data_est_charge', 26 ); } add_action( 'init', 'wpcargo_manipulate_shipment_column_table_callback' ); add_action( 'plugins_loaded', 'wpcargo_manipulate_shipment_column_table_callback' );
Codes to add new columns
Adding header column
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_header", "wpcfe_shipment_table_header_callback");
Adding data column
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; } add_action("wpcfe_shipment_table_data", "wpcfe_shipment_table_data_callback");
Adding Custom Columns With File Content
function wpcfe_shipment_table_header_callback_custom(){ echo "<th>Files</th>"; } add_action('wpcfe_shipment_table_header', 'wpcfe_shipment_table_header_callback_custom', 99); function wpcfe_shipment_table_data_callback_custom( $shipment_id ){ $attachment_id = get_post_meta($shipment_id, 'wpcargo_custom_file', true); $exploded_id = explode(',', $attachment_id); array_shift($exploded_id); $data = "<td>"; foreach($exploded_id as $id){ $data .= '<img src="'.wp_get_attachment_url($id).'" style="width: 30%;" />'; } $data .= "</td>"; echo $data; } add_action("wpcfe_shipment_table_data", "wpcfe_shipment_table_data_callback_custom", 99, 1);