How to Extract Multiple Package Piece Types and Display on Shipments Table
First off, let’s create a custom function that will extract package piece types:
function my_custom_peice_type_extractor($shipment_id){ $str_result = ""; $packages = maybe_unserialize(get_post_meta($shipment_id, 'wpc-multiple-package', true)) ?: array(); if(is_array($packages) && !empty($packages)){ foreach($packages as $package){ $package_quant = (int)($package['wpc-pm-qty'] ?: 1); $package_peice_type = $package['wpc-pm-piece-type'] ?: 'Standard Box'; $str_result .= "{$package_quant} {$package_peice_type}, "; } $str_result = rtrim($str_result, ', '); } return $str_result; }
After creating the function, add custom table header and data on shipments table:
function wpcc_shipment_table_header_action_callback(){ echo "<th class='no-space='>".__('Piece Type', 'wpcargo')."</th>"; } function wpcc_shipment_table_data_action_callback( $shipment_id ){ echo "<td class='no-space='>".my_custom_peice_type_extractor($shipment_id)."</td>"; } add_action('wpcfe_shipment_table_header', 'wpcc_shipment_table_header_action_callback'); add_action('wpcfe_shipment_table_data', 'wpcc_shipment_table_data_action_callback');
The result would look something like this: