• Resolved AvanorHealthcare

    (@avanorhealthcare)


    Hi

    I’ve having an issue with currency on the Invoice PDF.

    Our default Woocommerce currency is Pound Sterling (£). We import orders in Woocommerce from ebay (using WP-Lister Pro for eBay), some of which are in Euro (€).

    Here is an order in WooCommerce in Euros:
    https://ibb.co/k4Y2wU

    However, the invoice PDF displays the delivery, grand total (ex VAT), VAT and Grand Total (inc VAT) values in Pound Sterling. The item details display in Euro:
    https://ibb.co/b8pLi9

    Is there a way of it displaying the correct currency?

    Here’s the invoice.php code:

    <table class=”order-details”>
    <thead>
    <tr>
    <th class=”quantity”><?php _e(‘Quantity’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
    <th class=”product”><?php _e(‘Product’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
    <th class=”price”><?php _e(‘Unit Price’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
    <th class=”price”><?php _e(‘VAT Rate’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
    <th class=”price”><?php _e(‘VAT’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
    <th class=”price”><?php _e(‘Subtotal’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
    </tr>
    </thead>
    <tbody>
    <?php $items = $this->get_order_items(); if( sizeof( $items ) > 0 ) : foreach( $items as $item_id => $item ) : ?>
    <tr class=”<?php echo apply_filters( ‘wpo_wcpdf_item_row_class’, $item_id, $this->type, $this->order, $item_id ); ?>”>
    <td class=”quantity”><?php echo $item[‘quantity’]; ?></td>
    <td class=”product”>
    <?php $description_label = __( ‘Description’, ‘woocommerce-pdf-invoices-packing-slips’ ); // registering alternate label translation ?>
    <span class=”item-name”><?php echo $item[‘name’]; ?></span>
    <?php do_action( ‘wpo_wcpdf_before_item_meta’, $this->type, $item, $this->order ); ?>
    <span class=”item-meta”><?php echo $item[‘meta’]; ?></span>
    <dl class=”meta”>
    <?php $description_label = __( ‘SKU’, ‘woocommerce-pdf-invoices-packing-slips’ ); // registering alternate label translation ?>
    <?php if( !empty( $item[‘sku’] ) ) : ?><dt class=”sku”><?php _e( ‘SKU:’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></dt><dd class=”sku”><?php echo $item[‘sku’]; ?></dd><?php endif; ?>
    </dl>
    <?php do_action( ‘wpo_wcpdf_after_item_meta’, $this->type, $item, $this->order ); ?>
    </td>
    <td class=”price”><?php echo $item[‘ex_single_price’]; ?></td>
    <td class=”price”><?php echo $item[‘tax_rates’]; ?></td>
    <td class=”price”><?php echo $item[‘line_subtotal_tax’]; ?></td>
    <td class=”price”><?php echo $item[‘order_price’]; ?></td>
    </tr>
    <?php endforeach; endif; ?>
    </tbody>
    <tfoot>
    <?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?>
    <tr class=”<?php echo $key; ?>”>
    <th class=”space” colspan=”2″></th>
    <th class=”description” colspan=”3″><?php echo $total[‘label’]; ?></th>
    <td class=”price”><span class=”totals-price”><?php echo $total[‘value’]; ?></span></td>
    </tr>
    <?php endforeach; ?>
    </tfoot>
    </table>

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    These totals are preformatted by WooCommerce, they come from the same function that is used for the woocommerce emails. Which currency switcher do you use? I know that the Aelia Currency Switcher and the Currency Switcher by realmag777 are both compatible. Or do you not use a currency switcher at all and is this all done by the ebay importer?

    Thread Starter AvanorHealthcare

    (@avanorhealthcare)

    Thanks for getting back to me.
    I don’t use a currency switcher. The order values etc (and currency) is all brought in by the ebay importer.

    regards
    Phil

    Plugin Contributor Ewout

    (@pomegranate)

    Hi Phil,
    In that case you will need to contact the developers of WP-Lister Pro for eBay – this plugin merely pulls those from WooCommerce (this is what the get_woocommerce_totals() method is doing in your template), using $order->get_order_item_totals(). These values already have the currency formatting applied to them.

    Looking at your screenshot though, it seems that this output may already have been customized with a filter, so I recommend checking with your own developer first to ask if they have made any changes here.

    Good luck!

    Thread Starter AvanorHealthcare

    (@avanorhealthcare)

    I’m the developer ?? I made a few minor tweaks to show a few specific details on the invoice.

    I’m not sure the WP-Lister Pro developers will be able to help with this, as the individual values for delivery, grand total (ex VAT), VAT and Grand Total (inc VAT) are definitely stored in Euro – see the Woocommerce order:
    https://ibb.co/k4Y2wU

    It appears to me that the get_woocommerce_totals() method your plugin uses is adding the default currency. Is there a way of displaying the values using in the get_woocommerce_totals() method without the currency formatting added by get_woocommerce_totals()?

    regards
    Phil

    Plugin Contributor Ewout

    (@pomegranate)

    Hello Phil,
    If you are the developer, you must be the one who has altered the order totals (showing “Grand Total (Ex VAT)”, “VAT” and “Grand Total (Inc VAT)”). The default $order->get_order_item_totals() function does not return these rows.
    My get_woocommerce_totals method does not apply nor use any currency, this is done by woocommerce in $order->get_order_item_totals(), my function receives these preformatted. But if you have overriden these totals at some point, you may have not included the currency in the wc_price call.
    An order can only have one currency, but if you do not pass that currency to wc_price, WooCommerce does not know about it.

    Thread Starter AvanorHealthcare

    (@avanorhealthcare)

    I’ve done some digging – and I’ve found the filter you were talking about!
    I’d completely forgotten about it. (I thought I’d just done some tweaks to the product lines)

    Here’s the code:

    add_filter( ‘wpo_wcpdf_woocommerce_totals’, ‘wpo_wcpdf_woocommerce_totals_custom’, 10, 2 );
    function wpo_wcpdf_woocommerce_totals_custom( $totals, $order ) {
    $totals = array(
    ‘subtotal’ => array(
    ‘label’ => __(‘Subtotal’, ‘wpo_wcpdf’),
    ‘value’ => $order->get_subtotal_to_display(),
    ),
    ‘shipping’ => array(
    ‘label’ => __(‘Delivery’, ‘wpo_wcpdf’),
    ‘value’ => wc_price( $order->get_shipping_total() + $order->get_shipping_tax() ),
    ),
    ‘totalextax’ => array(
    ‘label’ => __(‘Grand Total (ex VAT)’, ‘wpo_wcpdf’),
    ‘value’ => wc_price( $order->get_total() – $order->get_total_tax() ),
    ),
    ‘totaltax’ => array(
    ‘label’ => __(‘VAT’, ‘wpo_wcpdf’),
    ‘value’ => wc_price( $order->get_total_tax() ),
    ),
    ‘total’ => array(
    ‘label’ => __(‘Grand Total (inc VAT)’, ‘wpo_wcpdf’),
    ‘value’ => wc_price( $order->get_total() )
    )
    );

    return $totals;
    }

    Looking at the above, it’s the ones that include wc_price that are being changed into Pound Sterling. What have I done wrong?

    Plugin Contributor Ewout

    (@pomegranate)

    You need to include the currency in the args for wc_price; https://docs.woocommerce.com/wc-apidocs/function-wc_price.html

    Thread Starter AvanorHealthcare

    (@avanorhealthcare)

    Thanks. Sorry, I don’t really understand the wc_price function. Can you clarify what I need to do?
    I would like it to display whatever the currency is on the specific woocommerce order (ie not necessarily the default currency).

    regards
    Phil

    Plugin Contributor Ewout

    (@pomegranate)

    Hello Phil,
    As explained in that link, the wc_price() function takes an array $args in the second argument to which you can pass the currency.
    As this concerns custom code that you have written yourself I cannot provide any additional support for it. The default output (if you disable your filter) will have the correct currency applied automatically.

    Thread Starter AvanorHealthcare

    (@avanorhealthcare)

    I can happily disable my filter. What does the default output display?

    I need the invoices to display the Subtotal, Delivery, Grand Total (ex VAT), Total VAT and Grand Total (inc VAT). How can I do that?

    Thread Starter AvanorHealthcare

    (@avanorhealthcare)

    I’ve disabled my filter, and checked the default output of the bottom section of the invoice:

    Shipping – [Shipping Method]
    Payment method – [Payment Method]
    Total [Grand Total inc VAT]
    (includes [VAT])

    The currency works correctly now (as you said it would), but I need the output to be:

    Delivery – [Shipping Cost, ex VAT]
    Grand Total (ex VAT) – [Grand Total ex VAT]
    Total VAT – [VAT]
    Grand Total (inc VAT) – [Grand Total inc VAT]

    Is there a way of changing the output to display that?

    Plugin Contributor Ewout

    (@pomegranate)

    Hi Phil,
    I’m glad to hear the issue is resolved when you disable the filter!

    To change the output, you can use the filter all you need to do then is pass the currency to wc_price(). Alternatively you can modify the columns and totals of the invoice with the customizer of our Premium Templates extension, but if all you need to do is change the currency then modifying your current filter is cheaper/quicker.

    Thread Starter AvanorHealthcare

    (@avanorhealthcare)

    I was able to change the columns manually, but not the totals. I don’t understand how to pass the currency to wc_price(). The link you provided earlier doesn’t make any sense to me at all.

    Is it possible to change the output to the following with the Premium extension:

    Delivery – [Shipping Cost, ex VAT]
    Grand Total (ex VAT) – [Grand Total ex VAT]
    Total VAT – [VAT]
    Grand Total (inc VAT) – [Grand Total inc VAT]

    regards
    Phil

    Plugin Contributor Ewout

    (@pomegranate)

    The link is from the official WooCommerce documentation, but I agree it’s somewhat lacking in the details. Perhaps the function source itself makes this more clear:

    https://github.com/woocommerce/woocommerce/blob/3.4.4/includes/wc-formatting-functions.php#L528-L540

    Yes, Premium Templates will let you define all totals and columns to your preference, see: Using the customizer

    Thread Starter AvanorHealthcare

    (@avanorhealthcare)

    The documentation is beyond me! ??

    The Premium Templates sounds like the solution. However, is the €27 charge required annually in order to use the customizer or is it just for support? What happens to my customizations if I don’t renew the subscription?

    regards
    Phil

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Problem with Currency’ is closed to new replies.