How to display loop of custom fields in invoice?
-
Hello, i have dynamical fields based on number of virtual products in cart. I would like to display them also in Invoice after order. Tried this code:
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_my_custom_field', 10, 2 ); function wpo_wcpdf_my_custom_field ($template_type, $order) { function order_has_virtual_product($order_id) { $order = wc_get_order($order_id); $items = $order->get_items(); $virtual_product_count = 0; foreach ($items as $item) { $product = $item->get_product(); if ($product->is_virtual()) { $virtual_product_count++; } } return $virtual_product_count; } $order_id = $order->get_id(); // Get the order ID from the $order object $virtual_product_count = order_has_virtual_product( $order_id ); for ( $i = 1; $i <= $virtual_product_count; $i++ ) { if ($template_type == 'invoice') { ?> <tr class="order_jmeno_ucastnika"> <th>ú?astníci kurzu:</th> <?php for ( $i = 1; $i <= $virtual_product_count; $i++ ) { ?> <td><?php echo $order->get_meta('order_jmeno_ucastnika' . $i); ?></td> <?php } ?> </tr> <?php } }}
When user order 2 virtual products or more there are generated fields with name order_jmeno_ucastnika1 order_jmeno_ucastnika2 .. etc
But in invoice is only first field “order_jmeno_ucastnika1” and others are not displayed.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How to display loop of custom fields in invoice?’ is closed to new replies.