1

Dear StackOverflow masters,

I'm looking for a method to create a ticket for each item that is included on a final order.

Let me break it down for you real easily with an example:

Here is a normal woocommerce invoice:

Qty      Product.         Price.    Total  
  15        T-Shirt           $1         $15

   2         Cup                $2         $4

 Order Total: $19 
 Total items: 17

What I need to do is generate a ticket for each item that was ordered so it can be printed.

So in this example, I would print 15 tickets saying "1 X T-shirt" and 2 tickets saying "1 X Cup".

Does anyone know any way to do this on woocommerce?

Thanks in advance

Randomhero
  • 11
  • 3

1 Answers1

0

As mentioned in this post:

How to get WooCommerce order details

you can get order info using the following

$order = wc_get_order( $order_id );
$items = $order->get_data();
then if you loop through them, you can get all the relevant data:

foreach ( $items as $item ) {
    $product_name = $item['name'];
    $product_id = $item['product_id'];
    $product_variation_id = $item['variation_id'];
}

then write the info to HTML file that can be printed later with the format and styling you want , something like:

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
foreach ( $items as $item ) {
        $product_name = $item['name'];
        $product_id = $item['product_id'];
        $product_variation_id = $item['variation_id'];
        $txt =<p style="color:black; font-size:13px;"> $product_id." ".$product_name;</p>
        fwrite($myfile, $txt);
    }
fclose($myfile);
Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
  • Kindly, you should update and test your code, if you want to have a chance to get this answer accepted and up voted… – LoicTheAztec Jul 20 '17 at 12:10