Make a filter to WooCommerce orderprint so we sort after most sold products (I have PHP code that fix it!)
Budget: $25 – $50 USD
When we print orders that are in status "Processing" we need to sort all selected orders so it print in order with the most sold products first and all of these together.
So it should make a summary of all sold products from the selected and find the most sold products and we need to print these first and then the next most sold products.
So if a order include this products it need to be printed with all the order orders that contains this sold product.
So if we have sold 2oo pcs. of one products we can have one person packing only these orders.
I have PHP code from plug-in that can do this as I want here.
But we just need to have the orderlist sorted this way and not in a plug-in. (Its because the plug-in we have dont work together with our new shipping system).
add_filter( 'wpo_wcol_summary', function( $flat_summary, $order_ids ) {
if ( ! empty( $flat_summary ) ) {
uasort( $flat_summary, function ( $a, $b ) {
return $b['quantity'] - $a['quantity'];
} );
}
return $flat_summary;
}, 10, 2 );
add_filter( 'wpo_wcol_order_ids', function( $order_ids ) {
return wpo_wcol_get_top_sale_order_ids( $order_ids );
}, 10, 1 );
add_filter( 'wpo_wcol_summary', function( $flat_summary, $order_ids ) {
if ( ! empty( $flat_summary ) ) {
$new_order_ids = wpo_wcol_get_top_sale_order_ids( $order_ids );
$new_flat_summary = array();
foreach ( $new_order_ids as $order_id ) {
if ( isset( $flat_summary[$order_id] ) ) {
$new_flat_summary[$order_id] = $flat_summary[$order_id];
}
}
$flat_summary = ! empty( $new_flat_summary ) ? $new_flat_summary : $flat_summary;
}
return $flat_summary;
}, 10, 2 );
function wpo_wcol_get_top_sale_order_ids( $order_ids ) {
if ( ! empty( $order_ids ) ) {
$ids = array();
foreach ( $order_ids as $order_id ) {
if ( $order = wc_get_order( $order_id ) ) {
foreach ( $order->get_items( 'line_item' ) as $item ) {
$product_id = $item['variation_id'] != 0 ? $item['variation_id'] : $item['product_id'];
$ids[$product_id][] = $order_id;
}
}
}
uasort( $ids, function( $a, $b ) { return count( $b ) - count( $a ); } );
$new_order_ids = array();
foreach ( $ids as $product_id => $order_ids ) {
foreach( $order_ids as $order_id ) {
if ( ! in_array( $order_id, $new_order_ids ) ) {
$new_order_ids[] = $order_id;
}
}
}
$order_ids = ! empty( $new_order_ids ) ? $new_order_ids : $order_ids;
}
return $order_ids;
}
So it should make a summary of all sold products from the selected and find the most sold products and we need to print these first and then the next most sold products.
So if a order include this products it need to be printed with all the order orders that contains this sold product.
So if we have sold 2oo pcs. of one products we can have one person packing only these orders.
I have PHP code from plug-in that can do this as I want here.
But we just need to have the orderlist sorted this way and not in a plug-in. (Its because the plug-in we have dont work together with our new shipping system).
add_filter( 'wpo_wcol_summary', function( $flat_summary, $order_ids ) {
if ( ! empty( $flat_summary ) ) {
uasort( $flat_summary, function ( $a, $b ) {
return $b['quantity'] - $a['quantity'];
} );
}
return $flat_summary;
}, 10, 2 );
add_filter( 'wpo_wcol_order_ids', function( $order_ids ) {
return wpo_wcol_get_top_sale_order_ids( $order_ids );
}, 10, 1 );
add_filter( 'wpo_wcol_summary', function( $flat_summary, $order_ids ) {
if ( ! empty( $flat_summary ) ) {
$new_order_ids = wpo_wcol_get_top_sale_order_ids( $order_ids );
$new_flat_summary = array();
foreach ( $new_order_ids as $order_id ) {
if ( isset( $flat_summary[$order_id] ) ) {
$new_flat_summary[$order_id] = $flat_summary[$order_id];
}
}
$flat_summary = ! empty( $new_flat_summary ) ? $new_flat_summary : $flat_summary;
}
return $flat_summary;
}, 10, 2 );
function wpo_wcol_get_top_sale_order_ids( $order_ids ) {
if ( ! empty( $order_ids ) ) {
$ids = array();
foreach ( $order_ids as $order_id ) {
if ( $order = wc_get_order( $order_id ) ) {
foreach ( $order->get_items( 'line_item' ) as $item ) {
$product_id = $item['variation_id'] != 0 ? $item['variation_id'] : $item['product_id'];
$ids[$product_id][] = $order_id;
}
}
}
uasort( $ids, function( $a, $b ) { return count( $b ) - count( $a ); } );
$new_order_ids = array();
foreach ( $ids as $product_id => $order_ids ) {
foreach( $order_ids as $order_id ) {
if ( ! in_array( $order_id, $new_order_ids ) ) {
$new_order_ids[] = $order_id;
}
}
}
$order_ids = ! empty( $new_order_ids ) ? $new_order_ids : $order_ids;
}
return $order_ids;
}