Snippets

Visser Labs Modify the Order Items export to show individual Product quantity per row

Created by Michael Visser
<?php
function custom_woo_ce_order_items_individual_output( $output, $order, $order_item ) {

  if( !empty( $order->order_items ) ) {
    // Check the Order Item has a Product ID
    if( !empty( $order_item->product_id ) ) {
      // Multiply the Order Item by the Quantity value
      if( !empty( $order_item->quantity ) ) {
        $size = $order_item->quantity;
        for( $i = 1; $i < $size; $i++ ) {
          $order_temp = (object)(array)$order;
          $output[] = apply_filters( 'woo_ce_order_items_individual', $order_temp, $order_item );
          unset( $order_temp );
        }
      }
    }
  }
  return $output;

}
add_filter( 'woo_ce_order_items_individual_output', 'custom_woo_ce_order_items_individual_output', 10, 3 );

function custom_woo_ce_order_items_individual_output_end( $output, $order ) {

  $size = count( $output );
  for( $i = 0; $i < $size; $i++ ) {
    $output[$i]->order_items_quantity = 1;
  }
  return $output;

}
add_filter( 'woo_ce_order_items_individual_output_end', 'custom_woo_ce_order_items_individual_output_end', 10, 2 );
?>

Comments (0)