WooCommerce PDF Invoices - Version 1.0.2

Version Description

  • December 13, 2013 =

  • Added: Attach pdf invoice to email type of your choice.

  • Added: Translation ready.

  • Added: Update and error notes to the settings page.

  • Improved: Notes to the settings page.

Download this release

Release Info

Developer baaaaas
Plugin Icon 128x128 WooCommerce PDF Invoices
Version 1.0.2
Comparing to
See all releases

Code changes from version 1.0.1 to 1.0.2

assets/screenshot-1.png DELETED
Binary file
assets/screenshot-2.png DELETED
Binary file
includes/class-admin.php CHANGED
@@ -5,11 +5,18 @@ class BEWPI_Admin {
5
  function __construct() {
6
  add_action( 'admin_init', array($this, 'register_settings' ));
7
  add_action( 'admin_menu', array($this, 'add_menu_item'));
8
-
9
- require BEWPI_PLUGIN_DIR . 'includes/class-invoice.php';
10
- add_filter( 'woocommerce_email_attachments', array('BEWPI_Invoice', 'generate_invoice'),10,3 );
11
  }
12
 
 
 
 
 
 
 
 
 
13
  function register_settings() {
14
  register_setting( 'be_woocommerce_pdf_invoices', 'be_woocommerce_pdf_invoices', array($this, 'validate_settings'));
15
  }
@@ -18,22 +25,31 @@ class BEWPI_Admin {
18
  add_submenu_page( 'woocommerce', 'Invoices by Bas Elbers', 'Invoices', 'manage_options', 'bewpi', array($this, 'show_settings_page') );
19
  }
20
 
21
- function validate_settings($settings)
22
- {
23
  $old_settings = get_option('be_woocommerce_pdf_invoices');
 
24
 
25
- if(isset($_FILES['logo']))
26
  {
27
- if ($_FILES['logo']['size'] <= 30000)
28
- {
29
- if ( preg_match('/(jpg|jpeg|png)$/', $_FILES['logo']['type']) )
30
- {
31
  $override = array('test_form' => false);
32
  $file = wp_handle_upload( $_FILES['logo'], $override );
33
  $settings['file_upload'] = $file['url'];
 
 
 
34
  }
 
 
 
35
  }
36
  }
 
 
 
 
 
37
  return $settings;
38
  }
39
 
5
  function __construct() {
6
  add_action( 'admin_init', array($this, 'register_settings' ));
7
  add_action( 'admin_menu', array($this, 'add_menu_item'));
8
+ add_action('init', array($this, 'load_textdomain_for_woocommerce_pdf_invoices'));
9
+ add_action( 'admin_notices', array($this, 'woocommerce_pdf_invoices_admin_notices' ));
 
10
  }
11
 
12
+ function woocommerce_pdf_invoices_admin_notices() {
13
+ settings_errors( 'woocommerce_pdf_invoices_notices' );
14
+ }
15
+
16
+ function load_textdomain_for_woocommerce_pdf_invoices() {
17
+ load_plugin_textdomain('woocommerce-pdf-invoices', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
18
+ }
19
+
20
  function register_settings() {
21
  register_setting( 'be_woocommerce_pdf_invoices', 'be_woocommerce_pdf_invoices', array($this, 'validate_settings'));
22
  }
25
  add_submenu_page( 'woocommerce', 'Invoices by Bas Elbers', 'Invoices', 'manage_options', 'bewpi', array($this, 'show_settings_page') );
26
  }
27
 
28
+ function validate_settings($settings) {
 
29
  $old_settings = get_option('be_woocommerce_pdf_invoices');
30
+ $errors;
31
 
32
+ if((isset($_FILES['logo']['name'])) && ($_FILES["logo"]["error"]==0))
33
  {
34
+ if($_FILES['logo']['size'] <= 50000){
35
+ if(preg_match('/(jpg|jpeg|png)$/', $_FILES['logo']['type'])){
 
 
36
  $override = array('test_form' => false);
37
  $file = wp_handle_upload( $_FILES['logo'], $override );
38
  $settings['file_upload'] = $file['url'];
39
+ }else{
40
+ add_settings_error('woocommerce_pdf_invoices_notices', esc_attr( 'settings_updated' ), __('Please upload image with extension jpg, jpeg or png.'), 'error');
41
+ $errors++;
42
  }
43
+ }else{
44
+ add_settings_error('woocommerce_pdf_invoices_notices', esc_attr( 'settings_updated' ), __('Please upload image less then 50kB.'), 'error');
45
+ $errors++;
46
  }
47
  }
48
+
49
+ if(!$errors){
50
+ add_settings_error('woocommerce_pdf_invoices_notices', esc_attr( 'settings_updated' ), __('Settings saved.'), 'updated');
51
+ }
52
+
53
  return $settings;
54
  }
55
 
includes/class-invoice.php CHANGED
@@ -2,13 +2,17 @@
2
 
3
  class BEWPI_Invoice {
4
 
 
 
 
 
5
  function generate_invoice($val, $id, $order){
6
- if($id == 'customer_invoice')
 
 
7
  {
8
  include(BEWPI_PLUGIN_DIR . '/mpdf/mpdf.php');
9
 
10
- $options = get_option('be_woocommerce_pdf_invoices');
11
-
12
  $items = $order->get_items();
13
 
14
  $today = date('d');
@@ -40,22 +44,6 @@ function generate_invoice($val, $id, $order){
40
  $mpdf->SetProtection(array('print'));
41
  $mpdf->SetDisplayMode('fullpage');
42
 
43
- // Get all items and output in table rows and datacells.
44
- $all_items;
45
- foreach ( $items as $item ) {
46
- $item_subtotal = $order->get_item_subtotal($item);
47
- $item_total = $item['qty'] * $item_subtotal;
48
- $formatted_item_subtotal = woocommerce_price($item_subtotal);
49
- $formatted_item_total = woocommerce_price($item_total);
50
-
51
- $all_items .= "<tr><td align='center'>" . $item['product_id'] . "</td>" .
52
- "<td align='center'>" . $item['qty'] . "</td>" .
53
- "<td>" . $item['name'] . "</td>" .
54
- "<td align='right'>" . $formatted_item_subtotal . "</td>" .
55
- "<td align='right'>" . $formatted_item_total . "</td>" .
56
- "</tr>";
57
- }
58
-
59
  // The HTML PDF invoice
60
  ob_start();
61
  ?>
@@ -160,17 +148,31 @@ function generate_invoice($val, $id, $order){
160
  </thead>
161
  <tbody>
162
  <!-- ITEMS HERE -->
163
- <?php echo $all_items; ?>
 
 
 
 
 
 
 
 
 
 
 
 
164
  <!-- END ITEMS HERE -->
165
  <tr>
166
  <td class="blanktotal" colspan="3" rowspan="6"></td>
167
  <td class="totals"><?php echo __( 'SUBTOTAL', 'woocommerce-pdf-invoices' ); ?></td>
168
  <td class="totals"><?php echo woocommerce_price($order_subtotal); ?></td>
169
  </tr>
 
170
  <tr>
171
  <td class="totals"><?php echo __( 'SALES TAX', 'woocommerce-pdf-invoices' ); ?></td>
172
  <td class="totals"><?php echo woocommerce_price($total_tax); ?></td>
173
  </tr>
 
174
  <tr>
175
  <td class="totals"><?php echo __( 'SHIPPING & HANDLING', 'woocommerce-pdf-invoices' ); ?></td>
176
  <td class="totals"><?php echo woocommerce_price($order->get_shipping()); ?></td>
2
 
3
  class BEWPI_Invoice {
4
 
5
+ function __construct(){
6
+ add_filter( 'woocommerce_email_attachments', array($this, 'generate_invoice'),10,3 );
7
+ }
8
+
9
  function generate_invoice($val, $id, $order){
10
+ $options = get_option('be_woocommerce_pdf_invoices');
11
+
12
+ if($id == $options['email_type'])
13
  {
14
  include(BEWPI_PLUGIN_DIR . '/mpdf/mpdf.php');
15
 
 
 
16
  $items = $order->get_items();
17
 
18
  $today = date('d');
44
  $mpdf->SetProtection(array('print'));
45
  $mpdf->SetDisplayMode('fullpage');
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  // The HTML PDF invoice
48
  ob_start();
49
  ?>
148
  </thead>
149
  <tbody>
150
  <!-- ITEMS HERE -->
151
+ <?php foreach ( $items as $item ) {
152
+ $item_subtotal = $order->get_item_subtotal($item);
153
+ $item_total = $item['qty'] * $item_subtotal;
154
+ $formatted_item_subtotal = woocommerce_price($item_subtotal);
155
+ $formatted_item_total = woocommerce_price($item_total); ?>
156
+ <tr>
157
+ <td align='center'><?php echo $item['product_id']; ?></td>
158
+ <td align='center'><?php echo $item['qty']; ?></td>
159
+ <td><?php echo $item['name']; ?></td>
160
+ <td align='right'><?php echo $formatted_item_subtotal; ?></td>
161
+ <td align='right'><?php echo $formatted_item_total; ?></td>
162
+ </tr>
163
+ <?php } ?>
164
  <!-- END ITEMS HERE -->
165
  <tr>
166
  <td class="blanktotal" colspan="3" rowspan="6"></td>
167
  <td class="totals"><?php echo __( 'SUBTOTAL', 'woocommerce-pdf-invoices' ); ?></td>
168
  <td class="totals"><?php echo woocommerce_price($order_subtotal); ?></td>
169
  </tr>
170
+ <?php if(get_option( 'woocommerce_calc_taxes' ) == 'yes') { ?>
171
  <tr>
172
  <td class="totals"><?php echo __( 'SALES TAX', 'woocommerce-pdf-invoices' ); ?></td>
173
  <td class="totals"><?php echo woocommerce_price($total_tax); ?></td>
174
  </tr>
175
+ <?php } ?>
176
  <tr>
177
  <td class="totals"><?php echo __( 'SHIPPING & HANDLING', 'woocommerce-pdf-invoices' ); ?></td>
178
  <td class="totals"><?php echo woocommerce_price($order->get_shipping()); ?></td>
includes/plugin.php CHANGED
@@ -5,6 +5,7 @@ function bewpi_get_options(){
5
 
6
  if(!$options){
7
  $defaults = array(
 
8
  'company_name' => get_option('woocommerce_email_from_name'),
9
  'company_slogan' => '',
10
  'file_upload' => '',
5
 
6
  if(!$options){
7
  $defaults = array(
8
+ 'email_type' => '',
9
  'company_name' => get_option('woocommerce_email_from_name'),
10
  'company_slogan' => '',
11
  'file_upload' => '',
includes/views/settings-page.php CHANGED
@@ -14,10 +14,13 @@
14
  width:670px;
15
  margin-bottom:7px;
16
  }
 
 
 
17
  </style>
18
  <div class="wrap">
19
- <h3>Woocommerce PDF Invoices Settings</h3>
20
- <p>Please fill in the settings below. Woocommerce PDF Invoices generates a PDF invoice based upon the customer order and attaches it to the confirmation email.</p>
21
 
22
  <form method="post" action="options.php" enctype="multipart/form-data">
23
  <?php
@@ -26,11 +29,27 @@
26
  $plugin_url = plugins_url();
27
  ?>
28
  <table class="form-table">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  <tr valign="top">
30
  <th scope="row"><strong>Company name:</strong></th>
31
  <td>
32
  <input required type="text" size="40" name="be_woocommerce_pdf_invoices[company_name]" value="<?php echo $options['company_name']; ?>" /><br/>
33
- <div style="font-style:italic;">
34
  <span style="color:grey;">Add your company name here.</span>
35
  <div>
36
  </td>
@@ -51,7 +70,7 @@
51
  <td>
52
  <input style="width:660px; margin-bottom:7px;" type="file" name="logo" accept="image/*" /><br />
53
  <div style="font-style:italic;">
54
- <span style="color:grey;">Add your custom company logo. You can leave it blank, the plugin will use your company name.</span>
55
  <div>
56
  <?php if($options['file_upload'] != ''){ ?>
57
  <style>
14
  width:670px;
15
  margin-bottom:7px;
16
  }
17
+ select{
18
+ margin-bottom:7px;
19
+ }
20
  </style>
21
  <div class="wrap">
22
+ <h3>WooCommerce PDF Invoices Settings</h3>
23
+ <p>Please fill in the settings below. WooCommerce PDF Invoices generates a PDF invoice based upon the customer order and attaches it to an email type of your choice.</p>
24
 
25
  <form method="post" action="options.php" enctype="multipart/form-data">
26
  <?php
29
  $plugin_url = plugins_url();
30
  ?>
31
  <table class="form-table">
32
+ <tr valign="top">
33
+ <th scope="row"><strong>Email type:</strong></th>
34
+ <td>
35
+ <select style="width: 210px;" id="selectEmailType" name="be_woocommerce_pdf_invoices[email_type]">
36
+ <option>-- Select --</option>
37
+ <option value="customer_processing_order" <?php selected($options['email_type'], 'customer_processing_order'); ?>>Customer processing order</option>
38
+ <option value="customer_completed_order" <?php selected($options['email_type'], 'customer_completed_order'); ?>>Customer completed order</option>
39
+ <option value="customer_invoice" <?php selected($options['email_type'], 'customer_invoice'); ?>>Customer invoice</option>
40
+ </select>
41
+ <input type="hidden" id="hfEmailType" value="<?php echo esc_attr($options['email_type']); ?>" />
42
+ <div style="font-style:italic;">
43
+ <span style="color:grey;">Select the type of email to attach the invoice to.</span>
44
+ <div>
45
+ </td>
46
+ </tr>
47
+
48
  <tr valign="top">
49
  <th scope="row"><strong>Company name:</strong></th>
50
  <td>
51
  <input required type="text" size="40" name="be_woocommerce_pdf_invoices[company_name]" value="<?php echo $options['company_name']; ?>" /><br/>
52
+ <div style="font-style:italic; margin-bottom:7px;">
53
  <span style="color:grey;">Add your company name here.</span>
54
  <div>
55
  </td>
70
  <td>
71
  <input style="width:660px; margin-bottom:7px;" type="file" name="logo" accept="image/*" /><br />
72
  <div style="font-style:italic;">
73
+ <span style="color:grey;">Add your custom company logo. Please upload image with a size behond 50kB. You don't have to upload any, the plugin will use your company name.</span>
74
  <div>
75
  <?php if($options['file_upload'] != ''){ ?>
76
  <style>
index.php CHANGED
@@ -1,21 +1,29 @@
1
  <?php
2
 
3
  /**
4
- * Plugin Name: Woocommerce PDF Invoices
5
- * Description: Generate PDF invoice and automatically attach to Woocommerce confirmation email.
6
- * Version: 1.0.1
7
  * Author: Bas Elbers
8
  * License: GPL2
9
  */
10
 
11
  if ( ! defined( 'ABSPATH' ) ) exit;
12
 
13
- define("BEWPI_VERSION", "1.0.0");
14
  define("BEWPI_PLUGIN_DIR", plugin_dir_path(__FILE__));
15
  define("BEWPI_PLUGIN_URL", plugins_url( '/' , __FILE__ ));
16
 
17
  require_once BEWPI_PLUGIN_DIR . 'includes/plugin.php';
18
- require BEWPI_PLUGIN_DIR . 'includes/class-admin.php';
19
- new BEWPI_Admin();
 
 
 
 
 
 
 
 
20
 
21
  ?>
1
  <?php
2
 
3
  /**
4
+ * Plugin Name: WooCommerce PDF Invoices
5
+ * Description: Generate PDF invoice and automatically attach to WooCommerce email type of your choice.
6
+ * Version: 1.0.2
7
  * Author: Bas Elbers
8
  * License: GPL2
9
  */
10
 
11
  if ( ! defined( 'ABSPATH' ) ) exit;
12
 
13
+ define("BEWPI_VERSION", "1.0.2");
14
  define("BEWPI_PLUGIN_DIR", plugin_dir_path(__FILE__));
15
  define("BEWPI_PLUGIN_URL", plugins_url( '/' , __FILE__ ));
16
 
17
  require_once BEWPI_PLUGIN_DIR . 'includes/plugin.php';
18
+ require_once BEWPI_PLUGIN_DIR . 'includes/class-invoice.php';
19
+ new BEWPI_Invoice;
20
+
21
+ if((is_admin()) && (!defined("DOING_AJAX") || !DOING_AJAX)) {
22
+
23
+ // ADMIN SECTION
24
+ require BEWPI_PLUGIN_DIR . 'includes/class-admin.php';
25
+ new BEWPI_Admin();
26
+
27
+ }
28
 
29
  ?>
lang/woocommerce-pdf-invoices.mo ADDED
Binary file
lang/woocommerce-pdf-invoices.po ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: WooCommerce PDF Invoices\n"
4
+ "POT-Creation-Date: 2013-12-13 14:48+0100\n"
5
+ "PO-Revision-Date: 2013-12-13 14:49+0100\n"
6
+ "Last-Translator: Bas Elbers <baselbers@hotmail.com>\n"
7
+ "Language-Team: \n"
8
+ "Language: en_GB\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.6.2\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "X-Poedit-KeywordsList: __;_e\n"
15
+ "X-Poedit-SearchPath-0: ../.\n"
16
+
17
+ #: .././includes/class-invoice.php:100
18
+ msgid "INVOICE"
19
+ msgstr ""
20
+
21
+ #: .././includes/class-invoice.php:109
22
+ msgid "INVOICE NUMBER: "
23
+ msgstr ""
24
+
25
+ #: .././includes/class-invoice.php:110
26
+ #, php-format
27
+ msgid "DATE: %02d-%02d-%04d"
28
+ msgstr ""
29
+
30
+ #: .././includes/class-invoice.php:119
31
+ msgid "TO:"
32
+ msgstr ""
33
+
34
+ #: .././includes/class-invoice.php:123
35
+ msgid "SHIP TO:"
36
+ msgstr ""
37
+
38
+ #: .././includes/class-invoice.php:132
39
+ msgid "Notes:"
40
+ msgstr ""
41
+
42
+ #: .././includes/class-invoice.php:142
43
+ msgid "SKU"
44
+ msgstr ""
45
+
46
+ #: .././includes/class-invoice.php:143
47
+ msgid "QUANTITY"
48
+ msgstr ""
49
+
50
+ #: .././includes/class-invoice.php:144
51
+ msgid "DESCRIPTION"
52
+ msgstr ""
53
+
54
+ #: .././includes/class-invoice.php:145
55
+ msgid "UNIT PRICE"
56
+ msgstr ""
57
+
58
+ #: .././includes/class-invoice.php:146
59
+ msgid "TOTAL"
60
+ msgstr ""
61
+
62
+ #: .././includes/class-invoice.php:167
63
+ msgid "SUBTOTAL"
64
+ msgstr ""
65
+
66
+ #: .././includes/class-invoice.php:172
67
+ msgid "SALES TAX"
68
+ msgstr ""
69
+
70
+ #: .././includes/class-invoice.php:177
71
+ msgid "SHIPPING & HANDLING"
72
+ msgstr ""
73
+
74
+ #: .././includes/class-invoice.php:181
75
+ msgid "TOTAL DUE"
76
+ msgstr ""
77
+
78
+ #: .././includes/class-invoice.php:198
79
+ #, php-format
80
+ msgid "Page %s of %s"
81
+ msgstr ""
readme.txt CHANGED
@@ -1,17 +1,17 @@
1
  === Plugin Name ===
2
  Contributors: Bas Elbers
3
  Donate link:
4
- Tags: wooCommerce pdf invoices, invoice, generate, pdf, wooCommerce, attachment, customer invoice, completed order, attach, automatic
5
  Requires at least: 3.5
6
- Tested up to: 3.7.1
7
- Stable tag: 1.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Simple plugin to generate a PDF invoice based upon the customers order and automatically attaches it to the customer invoice email.
12
 
13
  == Description ==
14
- This plugin simply generates a PDF Invoice based upon the customers order and automatically attaches it to the customer invoice email.
15
  Download the WooCommerce PDF Invoices plugin now!
16
  The plugin adds a new settings page as a submenu within the WooCommerce main menu and gives the option to customize your invoice by adding a company logo, company address, additional company information, refunds policies, conditions etc. and more!
17
 
@@ -29,7 +29,7 @@ No more singly drafting invoices and manually sending invoices to your customers
29
  - Add additional company information
30
  - Add refunds policies, conditions etc.
31
  - Auto generating invoice numbers
32
- - Auto attaching to the customer invoice email
33
 
34
  == Frequently Asked Questions ==
35
 
@@ -62,12 +62,19 @@ The manual installation method involves downloading our eCommerce plugin and upl
62
 
63
  == Changelog ==
64
 
 
 
 
 
 
 
 
65
  = 1.0.1 - December 7, 2013 =
66
 
 
67
  - Improved: Changed individual address fields to one textarea field.
68
  - Improved: Automatic linebreaks in textarea fields.
69
- - Improved: Added notes to the settings page.
70
 
71
- = 1.0 - December 6, 2013 =
72
 
73
  - Initial release.
1
  === Plugin Name ===
2
  Contributors: Bas Elbers
3
  Donate link:
4
+ Tags: woocommerce pdf invoices, invoice, generate, pdf, woocommerce, attachment, email, completed order, customer invoice, processing order, attach, automatic
5
  Requires at least: 3.5
6
+ Tested up to: 3.8
7
+ Stable tag: 1.0.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Simple plugin to generate a PDF invoice based upon the customers order and automatically attaches it to the email type of your choice.
12
 
13
  == Description ==
14
+ This plugin simply generates a PDF Invoice based upon the customers order and automatically attaches it to the email type of your choice.
15
  Download the WooCommerce PDF Invoices plugin now!
16
  The plugin adds a new settings page as a submenu within the WooCommerce main menu and gives the option to customize your invoice by adding a company logo, company address, additional company information, refunds policies, conditions etc. and more!
17
 
29
  - Add additional company information
30
  - Add refunds policies, conditions etc.
31
  - Auto generating invoice numbers
32
+ - Attach pdf invoice to email type of your choice
33
 
34
  == Frequently Asked Questions ==
35
 
62
 
63
  == Changelog ==
64
 
65
+ = 1.0.2 - December 13, 2013 =
66
+
67
+ - Added: Attach pdf invoice to email type of your choice.
68
+ - Added: Translation ready.
69
+ - Added: Update and error notes to the settings page.
70
+ - Improved: Notes to the settings page.
71
+
72
  = 1.0.1 - December 7, 2013 =
73
 
74
+ - Added: Notes to the settings page.
75
  - Improved: Changed individual address fields to one textarea field.
76
  - Improved: Automatic linebreaks in textarea fields.
 
77
 
78
+ = 1.0.0 - December 6, 2013 =
79
 
80
  - Initial release.