WordPress.org

Plugin Directory

Test out the new Plugin Directory and let us know what you think.

WooCommerce PDF Invoices

Automatically generate and attach customizable PDF Invoices to WooCommerce emails and connect with Dropbox, Google Drive, OneDrive or Egnyte.

How to add your custom template?

To getting started, copy the default template files (including folder) called plugins/woocommerce-pdf-invoices/includes/templates/invoices/simple/micro to uploads/bewpi-templates/invoices/simple and rename the template folder micro. The plugin will now detect the template and makes it available for selection within the template settings tab. Now go ahead en start making some changes to the template files! :)

How to add a fee to the invoice?

To add a fee to WooCommerce and your invoice, simply add the following action to your themes functions.php.

function add_woocommerce_fee() {
    global $woocommerce;

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $amount = 5;
    $woocommerce->cart->add_fee( 'FEE_NAME', $amount, true, 'standard' );
}
add_action( 'woocommerce_cart_calculate_fees','add_woocommerce_fee' );

How to hide order item meta?

To hide order item meta from the invoice, simply add the following filter to your themes functions.php.

/**
 * Hide order itemmeta on WooCommerce PDF Invoices' invoice template.
 *
 * @param array $hidden_order_itemmeta itemmeta.
 *
 * @return array
 */
function bewpi_alter_hidden_order_itemmeta( $hidden_order_itemmeta ) {
    $hidden_order_itemmeta[] = '_wc_cog_item_cost';
    $hidden_order_itemmeta[] = '_wc_cog_item_total_cost';
    $hidden_order_itemmeta[] = '_subscription_interval';
    $hidden_order_itemmeta[] = '_subscription_length';
    // end so on..
    return $hidden_order_itemmeta;
}
add_filter( 'bewpi_hidden_order_itemmeta', 'bewpi_alter_hidden_order_itemmeta', 10, 1 );

How to change the common PDF options?

To change the more common options of the PDF, use below example.

function custom_bewpi_mpdf_options( $options ) {
    $options['mode'] = '';
    $options['format'] = ''; // use [format]-L or [format]-P to force orientation (A4-L will be size A4 with landscape orientation)
    $options['default_font_size'] = 0;
    $options['default_font'] = 'opensans';
    $options['margin_left'] = 14;
    $options['margin_right'] = 14;
    $options['margin_top'] = 14;
    $options['margin_bottom'] = 0;
    $options['margin_header'] = 14;
    $options['margin_footer'] = 6;
    $options['orientation'] = 'P'; // Also try to force with format option

    return $options;
}
add_filter( 'bewpi_mpdf_options', 'custom_bewpi_mpdf_options' );

How to change the more advanced PDF options?

To fully customize the PDF, use below code. This filter gives you full control over the mPDF library. Check the mPDF manual for more info.

function bewpi_mpdf( $mpdf ) {
    // change the direction of the invoice to RTL
    $mpdf->SetDirectionality( 'rtl' );

    return $mpdf;
}
add_filter( 'bewpi_mpdf', 'bewpi_mpdf' );

How to display invoice download button on specific template files?

Add below code for example to your "thankyou" page or "customer-completed-order" email template.

echo do_shortcode( '[bewpi-download-invoice title="Download (PDF) Invoice {formatted_invoice_number}" order_id="' . $order->id . '"]' );

For use in WordPress editor use below shortcode. This will only work if you replace "{ORDER_ID}" with an actual order id.

[bewpi-download-invoice title="Download (PDF) Invoice {formatted_invoice_number}" order_id="{ORDER_ID}"]

Note: Download button will only be displayed when PDF exists and order has been paid.

Logo image shows a red cross?

By default the relative path is used for better performance, try to base64 the image. Also read the sticky topic on the support forum for more solutions!

function convert_company_logo_to_base64( $company_logo_path ) {
    $company_logo_url = str_replace( '..', get_site_url(), $company_logo_path );
    $type = pathinfo( $company_logo_url, PATHINFO_EXTENSION );
    $data = wp_remote_fopen( $company_logo_url );
    $base64 = 'data:image/' . $type . ';base64,' . base64_encode( $data );
    return $base64;
}
add_filter( 'bewpi_company_logo_url', 'convert_company_logo_to_base64' );

How to skip invoice generation based on specific payment methods?

Add the name of the payment method to the array.

function bewpi_attach_invoice_excluded_payment_methods( $payment_methods ) {
    return array( 'bacs', 'cod', 'cheque', 'paypal' );
}
add_filter( 'bewpi_attach_invoice_excluded_payment_methods', 'bewpi_attach_invoice_excluded_payment_methods', 10, 2 );

How to allow specific roles to download invoice?

Add the name of the role to the array. By default shop managers and administrators are allowed to download invoices.

function bewpi_allowed_roles_to_download_invoice($allowed_roles) {
    // available roles: shop_manager, customer, contributor, author, editor, administrator
    $allowed_roles[] = "editor";
    // end so on..
    return $allowed_roles;
}
add_filter( 'bewpi_allowed_roles_to_download_invoice', 'bewpi_allowed_roles_to_download_invoice', 10, 2 );

How to alter formatted invoice number?

Add following filter function to your functions.php within your theme.

function alter_formatted_invoice_number( $formatted_invoice_number, $invoice_type ) {
   if ( $invoice_type === 'global' ) { // simple or global.
      // add M for global invoices.
      return 'M' . $formatted_invoice_number;
   }
   return $formatted_invoice_number;
}
add_filter( 'bewpi_formatted_invoice_number', 'alter_formatted_invoice_number', 10, 2 );

How to add custom fields/meta-data to the PDF invoice template?

To add custom fields to the PDF invoice, a custom template is required. See FAQ on how to create a custom template. Use below code to display the meta-data. Replace META_KEY with the actual name of the custom field. Ask the author of the third party plugin if you don't know the name of the custom field.

<?php echo get_post_meta( $this->order->id, 'META_KEY', true ); ?>

Requires: 4.0 or higher
Compatible up to: 4.7.3
Last Updated: 3 weeks ago
Active Installs: 10,000+

Ratings

4.9 out of 5 stars

Support

38 of 72 support threads in the last two months have been marked resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1
100,1,1
100,1,1 100,1,1 100,1,1 100,1,1
100,2,2 100,2,2 100,1,1 100,1,1
100,1,1 100,3,3 100,2,2
100,1,1 100,1,1 100,2,2 50,2,1
100,1,1
100,1,1
0,1,0 100,1,1
100,1,1 100,1,1
100,1,1 100,1,1 100,1,1
100,1,1 100,1,1 100,1,1 100,1,1
100,1,1 100,1,1 100,1,1
100,1,1 100,1,1 100,1,1 100,1,1 100,1,1
100,2,2 100,1,1 100,1,1 100,1,1 50,2,1 100,1,1 100,1,1 100,1,1
100,1,1
100,1,1
100,1,1 100,1,1
100,1,1 100,1,1
100,2,2 100,1,1 100,1,1 100,2,2 50,2,1 100,3,3 100,1,1
100,1,1
100,1,1 100,1,1 100,1,1 100,1,1
100,1,1
100,2,2 100,1,1 100,1,1 100,1,1 50,2,1
100,2,2
100,1,1
100,1,1
100,1,1
50,2,1
100,1,1
100,1,1 0,1,0