@update — Working and fully functional
Yes, you can edit the default templates to fit your needs, without buying the premium one, but you need inside your active child theme or theme (if it doesn't exist yet):
- To create a folder named
woocommerce
- Copy folder from
plugins
> woocommerce-pdf-invoices-packing-slips
> templates
> pdf
to this newly fresh created woocommerce
folder.
- Inside this
pdf
folder, rename simple
subfolder with something like custom1
(or whatever you want).
- Activate your
custom1
pdf template, going in admin backend at:
WooCommerce
> PDF Invoices
> Template
(tab), select custom1
* in and **save.
Now in your active theme > woocommerce
> pdf
> custom1
you can customize the templates files included to feet your needs.
Get reed of the double tax display: the problem is in the foreach
loop.
1. Retrieving the slug (key name) for VAT duplicate value:
As you say, adding something inside this loop make it reproduce in each displayed element.
Here we are going to display the key
names or slugs just after the corresponding values
:
<?php foreach( $wpo_wcpdf->get_woocommerce_totals() as $key => $total ) : ?>
<tr class="<?php echo $key; ?>">
<td class="no-borders"></td>
<!-- we display the index value in here, below. -->
<th class="description"><?php echo $total['label'] . " (The key is '" . $key . "') " ;?></th>
<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
</tr>
<?php endforeach; ?>
Now if you generate the pdf invoice you will get at each line a different $key
name or slug (just after the corresponding values).
2. Adding a conditional in the loop to avoid displayed repetition:
Now that you know the key
name of the duplicated element you can act on the loop with an if()
statement inside it. You will have to replace 'the_key_name'
by the real key
name of the duplicated item:
<?php foreach( $wpo_wcpdf->get_woocommerce_totals() as $key => $total ) :
// As long as $key is NOT 'the_key_name' the item line is displayed
if ($key != 'the_key_name'){ ?>
<tr class="<?php echo $key; ?>">
<td class="no-borders"></td>
<th class="description"><?php echo $total['label']</th>
<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
</tr>
<?php }
endforeach; ?>
Now if you generate the pdf invoice, the duplicated item has disappeared completely from it.
Et voilà… Bon appétit :)