Index: lib/class.yith-invoice.php
diff --git a/lib/class.yith-invoice.php b/lib/class.yith-invoice.php
index 1d9292a836195083935ca63504c43df510ce3cf6..da3eecc0542c83b57d99a73b46fee2eb7acb1083 100644
--- a/lib/class.yith-invoice.php
+++ b/lib/class.yith-invoice.php
@@ -77,6 +77,13 @@ if ( ! class_exists ( 'YITH_Invoice' ) ) {
}
public function get_formatted_invoice_number () {
+ // Call the woocommerce_invoice_number filter and let third-party plugins set a number.
+ // Default is null, so we can detect whether a plugin has set the invoice number
+ $third_party_invoice_number = apply_filters( 'woocommerce_invoice_number', null, $this->order->id );
+ if ($third_party_invoice_number !== null) {
+ return $third_party_invoice_number;
+ }
+
$formatted_invoice_number = get_option ( 'ywpi_invoice_number_format' );
$formatted_invoice_number = str_replace (
@@ -144,20 +151,28 @@ if ( ! class_exists ( 'YITH_Invoice' ) ) {
return;
}
+ $third_party = apply_filters('woocommerce_invoice_number_by_plugin', false);
+
$this->date = time ();
$date = getdate ( $this->date );
$year = $date[ 'year' ];
- $this->number = $this->get_new_invoice_number ();
- $this->prefix = get_option ( 'ywpi_invoice_prefix' );
- $this->suffix = get_option ( 'ywpi_invoice_suffix' );
- $this->save_path = $year . "/invoice_" . $this->number . ".pdf";
+ if ($third_party) {
+ // Invoice numbers are handled by a third-party plugin
+ $this->number = apply_filters('woocommerce_generate_invoice_number', $this->order->get_order_number(), $this->order);
+ } else {
+ // This plugin should create invoice numbers
+ $this->number = $this->get_new_invoice_number ();
+ $this->prefix = get_option ( 'ywpi_invoice_prefix' );
+ $this->suffix = get_option ( 'ywpi_invoice_suffix' );
+ update_post_meta ( $this->order->id, '_ywpi_invoice_prefix', $this->prefix );
+ update_post_meta ( $this->order->id, '_ywpi_invoice_suffix', $this->suffix );
+ }
+ $this->save_path = $year . "/" . sanitize_file_name("invoice_" . $this->number . ".pdf");
$this->exists = true;
update_post_meta ( $this->order->id, '_ywpi_invoiced', $this->exists );
update_post_meta ( $this->order->id, '_ywpi_invoice_number', $this->number );
- update_post_meta ( $this->order->id, '_ywpi_invoice_prefix', $this->prefix );
- update_post_meta ( $this->order->id, '_ywpi_invoice_suffix', $this->suffix );
update_post_meta ( $this->order->id, '_ywpi_invoice_date', $this->date );
update_post_meta ( $this->order->id, '_ywpi_invoice_path', $this->save_path );
@@ -165,7 +180,9 @@ if ( ! class_exists ( 'YITH_Invoice' ) ) {
add_action ( 'ywpi_before_template_generation', array ( $this, 'init_template_generation_actions' ) );
$this->save_file ( $pdf_path );
- update_option ( 'ywpi_invoice_number', $this->number + 1 );
+ if (!$third_party) {
+ update_option ( 'ywpi_invoice_number', $this->number + 1 );
+ }
}
/**
Index: lib/class.yith-shipping.php
diff --git a/lib/class.yith-shipping.php b/lib/class.yith-shipping.php
index 2900f02a0ac15282452862736d2fa67f64253467..7375be27032d77a90a0d417d31c350da1a2635e3 100644
--- a/lib/class.yith-shipping.php
+++ b/lib/class.yith-shipping.php
@@ -77,7 +77,7 @@ if ( ! class_exists( 'YITH_Shipping' ) ) {
return;
}
- $this->save_path = $this->document_type . "_" . $this->order->get_order_number() . ".pdf";
+ $this->save_path = sanitize_file_name( $this->document_type . "_" . $this->order->get_order_number() . ".pdf" );
$this->exists = true;
update_post_meta( $this->order->id, '_ywpi_has_shipping_list', $this->exists );
Index: plugin-options/documents-options.php
diff --git a/plugin-options/documents-options.php b/plugin-options/documents-options.php
index 14dd35194a347f4efa96921ad13e235ea560bf66..1cd3c44fe31e51ab982197d0ce75c5deddbd5fe2 100644
--- a/plugin-options/documents-options.php
+++ b/plugin-options/documents-options.php
@@ -143,6 +143,23 @@ $general_options = array(
)
);
+// If a third-party numbering plugin is taking responsibility for invoice numbers,
+// show a link to the config page and remove the counter settings
+if (apply_filters('woocommerce_invoice_number_by_plugin', false)) {
+ $config_link = esc_attr(apply_filters('woocommerce_invoice_number_configuration_link', null));
+ $desc = __( 'Invoice numbers are created by a third-party extension.', 'yith-woocommerce-pdf-invoice');
+ if ($config_link) {
+ $desc .= ' '.sprintf(__( 'Configure it here.', 'yith-woocommerce-pdf-invoice'), $config_link);
+ }
+ $general_options['documents']['section_invoice_settings']['desc'] = ''.$desc.'';
+ unset($general_options['documents']['next_invoice_number']);
+ unset($general_options['documents']['next_invoice_year']);
+ unset($general_options['documents']['invoice_prefix']);
+ unset($general_options['documents']['invoice_suffix']);
+ unset($general_options['documents']['invoice_number_format']);
+ unset($general_options['documents']['invoice_reset']);
+}
+
$general_options['documents'] = $intro_tab + $general_options['documents'];
return $general_options;