• Resolved cedec

    (@cedec)


    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

    
    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

    (@webtoffeesupport)

    Hi @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.

    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.

Viewing 1 replies (of 1 total)
  • The topic ‘Sort by new column’ is closed to new replies.