How create invoices in the shop base currency with the WooCommerce PDF Invoices plugin

by Oscar on 19 October, 2018

The WooCommerce PDF Invoices by Bas Elbers is one of the most popular plugins to generates invoices and packing slips available in the WordPress plugin repository.

This plugin is fully compatible with Price Based on Country and generates the invoices in the customer currency; but if you need the invoices in the shop base currency, you can build a customization using the WCPBC_Order_Base_Currency class.

The following snippet replaces the WooCommerce order class by WCPBC_Order_Base_Currency before the plugin generates the invoice. WooCommerce PDF Invoices will instance an object of WCPBC_Order_Base_Currency and uses the totals expressed in shop base currency to make the invoice.

function my_order_class( $classname, $order_type, $order_id ) {
    $classname = 'WCPBC_Order_Base_Currency';
    return $classname;
}

function remove_order_class( $value = '' ) {
    remove_filter('woocommerce_order_class', 'my_order_class', 10, 3 );
    return $value;
}

function init_base_curency_order_class( $value = '' ) {
    if ( isset( $_GET['bewpi_action'] ) && ! in_array( wc_clean( $_GET['bewpi_action'] ), array( 'update', 'create', 'debug' ) ) ) {
        return $value;
    }
    add_filter( 'woocommerce_order_class', 'my_order_class', 10, 3 );
    return $value;
}

Upgrading to Price Based on Country Pro

WCPBC_Order_Base_Currency class is available since WooCommerce Price Based on Country Pro 2.4. If you do not upgrade to Pro version yet, you can buy a license with just a couple of clicks from the pricing page.

Leave a Reply