Title: Sort by new column
Last modified: August 24, 2023

---

# Sort by new column

 *  Resolved [cedec](https://wordpress.org/support/users/cedec/)
 * (@cedec)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/sort-by-new-column/)
 * Hi
   I have created a new column with data which are product storage locations.
   Can I sort products by new data when printing Packing slip?Thanks
 *     ```wp-block-code
       add_filter('wf_pklist_alter_product_table_head', 'wt_pklist_alter_product_columns', 10, 3);
       function wt_pklist_alter_product_columns($columns_list_arr, $template_type, $order)
       {
   
       /* adding a new custom column with text align right */
       $columns_list_arr['new_col']='<th class="wfte_product_table_head_new_col wfte_text_right" col-type="new_col">Miejsce magazyn</th>';
   
       return $columns_list_arr;
       }
   
   
       add_filter('wf_pklist_package_product_table_additional_column_val', 'wt_pklist_package_add_custom_col_vl', 10, 6);
       function wt_pklist_package_add_custom_col_vl($column_data, $template_type, $columns_key, $_product, $item, $order)
       {
       if($columns_key=='new_col')
       {		
             $column_data = $_product->get_meta('miejsce_magazyn' );                 
       }
       return $column_data;
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Support [WebToffee Support](https://wordpress.org/support/users/webtoffeesupport/)
 * (@webtoffeesupport)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/sort-by-new-column/#post-17029269)
 * Hi [@cedec](https://wordpress.org/support/users/cedec/),
 * Thank you for reaching out.
 * Below is the sample code snippet that you can use to sort the packing slip based
   on a custom column.
 *     ```wp-block-code
       add_filter( 'wf_pklist_alter_package_order_items', 'wf_pklist_sort_item_based_on_location', 10, 3 );
       function wf_pklist_sort_item_based_on_location( $order_package, $template_type, $order ) {
       	if ( $template_type == 'packinglist' ) {
       		$location = array();
       		foreach($order_package as $key =>$value)
       		{
       			$product_id = $value['extra_meta_details']['_product_id'][0];
       			$product = wc_get_product($product_id);
       			$locations[]  = $product->get_meta('miejsce_magazyn');                 
       		}
       		if(is_array($locations)){
       			array_multisort( $locations, SORT_ASC, $order_package );
       		}
       	}
       	return $order_package;
       }
       ```
   
 * If you’re looking to enhance your packing slip’s features or need further customization
   assistance, you might want to consider our premium addon, the [WooCommerce PDF Invoices, packing slips and credit notes](https://www.webtoffee.com/product/woocommerce-pdf-invoices-packing-slips/).

Viewing 1 replies (of 1 total)

The topic ‘Sort by new column’ is closed to new replies.

 * ![](https://ps.w.org/print-invoices-packing-slip-labels-for-woocommerce/assets/
   icon-256x256.gif?rev=3123111)
 * [WebToffee WooCommerce PDF Invoices, Packing Slips, Delivery Notes & Shipping Labels](https://wordpress.org/plugins/print-invoices-packing-slip-labels-for-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/print-invoices-packing-slip-labels-for-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/print-invoices-packing-slip-labels-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/print-invoices-packing-slip-labels-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/print-invoices-packing-slip-labels-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/print-invoices-packing-slip-labels-for-woocommerce/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [WebToffee Support](https://wordpress.org/support/users/webtoffeesupport/)
 * Last activity: [2 years, 9 months ago](https://wordpress.org/support/topic/sort-by-new-column/#post-17029269)
 * Status: resolved