WordPress.org

Plugin Directory

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.

function add_hidden_order_items( $order_items ) {
    $order_items[] = '_subscription_interval';
    $order_items[] = '_subscription_length';
    // end so on...

    return $order_items;
}
add_filter( 'woocommerce_hidden_order_itemmeta', 'add_hidden_order_items' );

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 to any template files. Replace {ORDER_ID} with the desired ID of the order to download the invoice from.

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

For use in WordPress editor:

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

Note: Download button will only show if PDF exists and order has been completed.

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 remove 'Paid' watermark based on specific order statuses?

By default the 'Paid' watermark won't display for 'Pending', 'On-Hold' and 'Auto-Draft' statuses.

function bewpi_paid_watermark_excluded_order_statuses($order_statuses, $order_id){
    // add (short) name of order status to exclude
    return array('pending', 'on-hold', 'auto-draft');
}
add_filter('bewpi_paid_watermark_excluded_order_statuses', 'bewpi_paid_watermark_excluded_order_statuses', 10, 2);

How to remove 'Paid' watermark based on specific payment methods?

By default 'BACS', 'Cash on Delivery' and 'Cheque' payment methods are excluded, so the invoice won't get marked as paid.

function exclude_payment_method_for_watermark($payment_methods, $order_id){
    // add (short) name of payment method to exclude
    return array('bacs', 'cod', 'cheque', 'paypal');
}
add_filter('bewpi_paid_watermark_excluded_payment_methods', 'exclude_payment_method_for_watermark', 10, 2);

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";

    return $allowed_roles;
}
add_filter('bewpi_allowed_roles_to_download_invoice', 'bewpi_allowed_roles_to_download_invoice', 10, 2);

Requires: 3.8 or higher
Compatible up to: 4.6.1
Last Updated: 2 days ago
Active Installs: 10,000+

Ratings

4.9 out of 5 stars

Support

1 of 26 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