Commit 90c85770 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

Finish support for all five invoice plugins

parent 812a2bbd
......@@ -364,6 +364,8 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic {
add_action ('wpo_wcpdf_process_template_order', array($this, 'thirdparty_wpo_wcpdf_create_number'), 10, 2);
// Disable the invoice number-related controls in the config of the other plugin
add_action ('woocommerce_page_wpo_wcpdf_options_page', array($this, 'thirdparty_wpo_wcpdf_remove_options'));
// If this plugin is enabled, but invoice numbers are not, display an information message and a link to the config
add_action ('woocommerce_page_wpo_wcpdf_options_page', array($this, 'thirdparty_wpo_wcpdf_configuration_link'));
}
/**
......@@ -412,6 +414,19 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic {
}
}
/**
* If this plugin is installed, but not configured for invoice numbers,
* Display an information message about this plugin and a link to its config.
*/
function thirdparty_wpo_wcpdf_configuration_link() {
global $wp_settings_fields;
if (!$this->invoicenumbers_activated()) {
$wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['display_number']['args']['description'] = '<i>' . sprintf($this->helper->__( 'The Open Tools Ordernumbers plugin is installed, but not configured to create invoice numbers. Configure it <a href="%s">here</a> to create invoice numbers.'), $this->invoicenumbers_config_link()) . '</i>';
}
return $settings;
}
/** ************************************************************
* Support for WooCommerce PDF Invoice (woocommerce-pdf-invoice) by WooThemes
......@@ -451,6 +466,19 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic {
protected function thirdparty_wc_delivery_notes_init() {
// Patch by OpenTools implements the generic interface, so nothing special needs to be done
// Setting use WP Settings API, remove the counter-specific settings
add_filter ('wcdn_get_settings_no_section', array($this, 'thirdparty_wc_delivery_notes_configuration_link'));
}
/**
* If this plugin is installed, but not configured for invoice numbers,
* Display an information message about this plugin and a link to its config.
*/
function thirdparty_wc_delivery_notes_configuration_link($settings) {
if (!$this->invoicenumbers_activated()) {
$settings['invoice_options']['desc'] = '<i>' . sprintf($this->helper->__( 'The Open Tools Ordernumbers plugin is installed, but not configured to create invoice numbers. Configure it <a href="%s">here</a> to create invoice numbers.'), $this->invoicenumbers_config_link()) . '</i>';
}
return $settings;
}
// END THIRD-PARTY PLUGIN SUPPORT
......
......@@ -192,10 +192,10 @@ class OpenToolsOrdernumbersBasic {
return (get_option('customize_'.$type, 'no')!='no');
}
public function ordernumbers_activated($default=false) {
return $this->numbers_activated('ordernumber');
return $default || $this->numbers_activated('ordernumber');
}
public function invoicenumbers_activated($default=false) {
return $this->numbers_activated('invoice');
return $default || $this->numbers_activated('invoice');
}
public function invoicenumbers_config_link($default=null) {
......@@ -480,17 +480,17 @@ class OpenToolsOrdernumbersBasic {
/**
* The generic function to retrieve a particular number
*/
function get_number($orderid, $order, $type = 'ordernumber') {
$stored_number = get_post_meta( $orderid, $this->ordernumber_meta.$type, 'true');
function get_number($default, $order, $type = 'ordernumber') {
$stored_number = get_post_meta( $order->id, $this->ordernumber_meta.$type, 'true');
if ($stored_number == $this->ordernumber_new_placeholder) {
// Check whether the order was now really created => create order number now
return $this->assign_new_ordernumber($orderid, $order, $type);
return $this->assign_new_ordernumber($order->id, $order, $type);
} elseif (!empty($stored_number)) {
// Order number already exists => simply return it
return $stored_number;
} else {
// No order number was created for this order, so simply use the orderid as default.
return $orderid;
return $default;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment