WooCommerce PDF Invoices & Packing Slips, shows Tax twice on pdf invoice

With WooCommerce and WooCommerce PDF Invoices & Packing Slips plugins, I have an issue. When PDF Invoices are generated, they shows the TAX two times:
Previous

I need to remove this duplication to make it looks like this:

Read More

After

I Know there are a few Premium Plugins with a mass of functions but I can not buy Premium Plugins anymore, as invested too much in other Plugins.

So I will need to make that little change. I can’t find any solution for this.

Can anyone help me with that?

Related posts

2 comments

  1. @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):

    1. To create a folder named woocommerce
    2. Copy folder from plugins > woocommerce-pdf-invoices-packing-slips > templates > pdf to this newly fresh created woocommerce folder.
    3. Inside this pdf folder, rename simple subfolder with something like custom1 (or whatever you want).
    4. 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 🙂

Comments are closed.