Skip to content
Snippets Groups Projects
Commit 69a82945 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Code generalization, mainly in connection with invoice numbers for other plugins

-) Add filters to query whether a third-party plugin claims responsibility for invoice numbers
-) Add filter to get the configuration link for this plugin
-) Move all configuration / documentation links to a class-wide property to avoide duplication
-) Generic function to check whether order/invoice numbers are enabled
parent 68f5e2aa
Branches
Tags
No related merge requests found
...@@ -330,7 +330,7 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic { ...@@ -330,7 +330,7 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic {
} }
function thirdparty_get_invoicenumber($default, $orderid) { function thirdparty_get_invoicenumber($default, $orderid) {
if (get_option('customize_invoice', 'no')!='no') { if ($this->invoicenumbers_activated()) {
$_of = new WC_Order_Factory(); $_of = new WC_Order_Factory();
$order = $_of->get_order($orderid); $order = $_of->get_order($orderid);
$number = $this->get_or_create_number($orderid, $order, 'invoice'); $number = $this->get_or_create_number($orderid, $order, 'invoice');
...@@ -381,7 +381,7 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic { ...@@ -381,7 +381,7 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic {
* The action to actually create the number and store it as post meta with the order * The action to actually create the number and store it as post meta with the order
*/ */
function thirdparty_wpo_wcpdf_create_number($type, $orderid) { function thirdparty_wpo_wcpdf_create_number($type, $orderid) {
if ($type=='invoice' && (get_option('customize_'.$type, 'no')!='no') ) { if ($type=='invoice' && $this->invoicenumbers_activated() ) {
$_of = new WC_Order_Factory(); $_of = new WC_Order_Factory();
$order = $_of->get_order($orderid); $order = $_of->get_order($orderid);
$number = $this->get_or_create_number($orderid, $order, $type); $number = $this->get_or_create_number($orderid, $order, $type);
...@@ -398,11 +398,12 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic { ...@@ -398,11 +398,12 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic {
*/ */
function thirdparty_wpo_wcpdf_remove_options() { function thirdparty_wpo_wcpdf_remove_options() {
global $wp_settings_fields; global $wp_settings_fields;
if (get_option('customize_invoice', 'no')!='no') { if ($this->invoicenumbers_activated()) {
$wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['display_number']['title'] = $this->helper->__('Display invoice number'); $wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['display_number']['title'] = $this->helper->__('Display invoice number');
$wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['display_number']['args']['description'] = $this->helper->__('The <a href="admin.php?page=wc-settings&tab=checkout&section=ordernumber">Open Tools Ordernumber plugin</a> has invoice numbers enabled and will generate invoice numbers for this plugin.' ); $wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['display_number']['args']['description'] = $this->helper->__('The <a href="admin.php?page=wc-settings&tab=checkout&section=ordernumber">Open Tools Ordernumber plugin</a> has invoice numbers enabled and will generate invoice numbers for this plugin.' );
unset($wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['next_invoice_number']); unset($wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['next_invoice_number']);
unset($wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['invoice_number_formatting']); unset($wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['invoice_number_formatting']);
unset($wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['yearly_reset_invoice_number']);
} else { } else {
$wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['display_number']['args']['description'] = $this->helper->__('To let the Open Tools ordernumber plugin create invoice numbers with your desired format, please enable invoices in <a href="admin.php?page=wc-settings&tab=checkout&section=ordernumber">that plugin\'s configuration page</a>.' ); $wp_settings_fields['wpo_wcpdf_template_settings']['invoice']['display_number']['args']['description'] = $this->helper->__('To let the Open Tools ordernumber plugin create invoice numbers with your desired format, please enable invoices in <a href="admin.php?page=wc-settings&tab=checkout&section=ordernumber">that plugin\'s configuration page</a>.' );
} }
...@@ -430,7 +431,7 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic { ...@@ -430,7 +431,7 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic {
// TODO: Modify the invoice number section text to hint at the installed order number plugin and how to enable it! // TODO: Modify the invoice number section text to hint at the installed order number plugin and how to enable it!
global $wp_settings_fields; global $wp_settings_fields;
return; return;
if (get_option('customize_invoice', 'no')!='no') { if ($this->invoicenumbers_activated()) {
// bewpi_template_settings -> invoice_number -> // bewpi_template_settings -> invoice_number ->
// -) bewpi_invoice_number_type // -) bewpi_invoice_number_type
// -) bewpi_reset_counter // -) bewpi_reset_counter
......
...@@ -18,6 +18,11 @@ class OpenToolsOrdernumbersBasic { ...@@ -18,6 +18,11 @@ class OpenToolsOrdernumbersBasic {
public $ordernumber_meta = "_oton_number_"; public $ordernumber_meta = "_oton_number_";
public $ordernumber_new_placeholder = "[New Order]"; public $ordernumber_new_placeholder = "[New Order]";
public $plugin_basename = ''; public $plugin_basename = '';
public $plugin_config_link = 'admin.php?page=wc-settings&tab=checkout&section=ordernumber';
public $plugin_url = 'https://wordpress.org/plugins/woocommerce-basic-ordernumbers/';
public $plugin_url_advanced = 'http://open-tools.net/woocommerce/advanced-ordernumbers-for-woocommerce.html';
public $plugin_url_docs = 'http://open-tools.net/documentation/advanced-order-numbers-for-woocommerce.html';
public $plugin_url_support = 'http://open-tools.net/support-forum/ordernumbers-for-woocommerce.html';
protected $helper = null; protected $helper = null;
protected $settings = array(); protected $settings = array();
...@@ -51,6 +56,15 @@ class OpenToolsOrdernumbersBasic { ...@@ -51,6 +56,15 @@ class OpenToolsOrdernumbersBasic {
*/ */
protected function initializeHooks() { protected function initializeHooks() {
$helper = OrdernumberHelperWooCommerce::getHelper(); $helper = OrdernumberHelperWooCommerce::getHelper();
// Information for other plugins
add_filter( 'opentools_ordernumbers_activated', array( &$this, 'ordernumbers_activated'));
add_filter( 'opentools_invoicenumbers_activated', array( &$this, 'invoicenumbers_activated'));
add_filter ('woocommerce_invoice_number_by_plugin', array( &$this, 'invoicenumbers_activated'));
add_filter ('woocommerce_order_number_by_plugin', array( &$this, 'ordernumbers_activated'));
add_filter ('woocommerce_invoice_number_configuration_link', array( &$this, 'invoicenumbers_config_link'));
add_filter ('woocommerce_order_number_configuration_link', array( &$this, 'ordernumbers_config_link'));
// CONFIGURATION SCREENS // CONFIGURATION SCREENS
add_filter( 'woocommerce_get_sections_checkout', array( &$this, 'add_admin_section')); add_filter( 'woocommerce_get_sections_checkout', array( &$this, 'add_admin_section'));
// The checkout settings page assumes all subpages are payment gateways, so we have to override this and manually pass our settings: // The checkout settings page assumes all subpages are payment gateways, so we have to override this and manually pass our settings:
...@@ -107,7 +121,7 @@ class OpenToolsOrdernumbersBasic { ...@@ -107,7 +121,7 @@ class OpenToolsOrdernumbersBasic {
'desc_tip' => true, 'desc_tip' => true,
'id' => 'opentools_ordernumbers_upgrade', 'id' => 'opentools_ordernumbers_upgrade',
'type' => 'opentools_ordernumbers_upgrade', 'type' => 'opentools_ordernumbers_upgrade',
'link' => 'http://open-tools.net/woocommerce/advanced-ordernumbers-for-woocommerce.html', 'link' => $this->plugin_url_advanced,
), ),
); );
return $settings; return $settings;
...@@ -116,7 +130,7 @@ class OpenToolsOrdernumbersBasic { ...@@ -116,7 +130,7 @@ class OpenToolsOrdernumbersBasic {
$settings = array(); $settings = array();
$settings[] = array( $settings[] = array(
'name' => $this->helper->__( 'Configure Order Numbers'), 'name' => $this->helper->__( 'Configure Order Numbers'),
'desc' => $this->helper->__( 'Configure the format and the counters of the order numbers in WooCommerce. For help, check out the plugin\'s <a href="http://open-tools.net/documentation/advanced-order-numbers-for-woocommerce.html">documentation at OpenTools</a>.'), 'desc' => sprintf( $this->helper->__( 'Configure the format and the counters of the order numbers in WooCommerce. For help, check out the plugin\'s <a href="%s">documentation at OpenTools</a>.'), esc_attr($this->plugin_url_docs)),
'type' => 'title', 'type' => 'title',
'id' => 'ordernumber_options' 'id' => 'ordernumber_options'
); );
...@@ -166,12 +180,42 @@ class OpenToolsOrdernumbersBasic { ...@@ -166,12 +180,42 @@ class OpenToolsOrdernumbersBasic {
protected function initializeSettingsOther() { protected function initializeSettingsOther() {
return array(); return array();
} }
/**
* Filters for other plugins to get information about this one, e.g.
* indicating whether invoice/order numbers are to be created by this plugin
* and getting the link to the configuration page.
*/
public function numbers_activated($type) {
return (get_option('customize_'.$type, 'no')!='no');
}
public function ordernumbers_activated($default=false) {
return $this->numbers_activated('ordernumber');
}
public function invoicenumbers_activated($default=false) {
return $this->numbers_activated('invoice');
}
public function invoicenumbers_config_link($default=null) {
// if ($this->invoicenumbers_activated())
return $this->plugin_config_link;
// else
// return $default;
}
public function ordernumbers_config_link($default=null) {
// if ($this->invoicenumbers_activated())
return $this->plugin_config_link;
// else
// return $default;
}
/** /**
* Add settings link to plugins page * Add settings link to plugins page
*/ */
public function ordernumber_add_settings_link( $links ) { public function ordernumber_add_settings_link( $links ) {
$link = '<a href="admin.php?page=wc-settings&tab=checkout&section=ordernumber">'. $this->helper->__( 'Settings' ) . '</a>'; $link = '<a href="'.esc_attr($this->plugin_config_link).'">'. $this->helper->__( 'Settings' ) . '</a>';
// Prepend the settings link: // Prepend the settings link:
array_unshift( $links, $link ); array_unshift( $links, $link );
// $links['settings'] = $link; // $links['settings'] = $link;
...@@ -179,15 +223,15 @@ class OpenToolsOrdernumbersBasic { ...@@ -179,15 +223,15 @@ class OpenToolsOrdernumbersBasic {
} }
public function ordernumber_plugin_row_meta( $links, $file ) { public function ordernumber_plugin_row_meta( $links, $file ) {
if ($file==$this->plugin_basename) { if ($file==$this->plugin_basename) {
$links['docs'] = '<a href="' . esc_url( 'http://open-tools.net/documentation/advanced-order-numbers-for-woocommerce.html' ) . '" title="' . esc_attr( $this->helper->__( 'Plugin Documentation' ) ) . '">' . $this->helper->__( 'Plugin Documentation' ) . '</a>'; $links['docs'] = '<a href="' . esc_url( $this->plugin_url_docs ) . '" title="' . esc_attr( $this->helper->__( 'Plugin Documentation' ) ) . '">' . $this->helper->__( 'Plugin Documentation' ) . '</a>';
$links['support'] = '<a href="' . esc_url( 'http://open-tools.net/support-forum/ordernumbers-for-woocommerce.html' ) . '" title="' . esc_attr( $this->helper->__( 'Support Forum' ) ) . '">' . $this->helper->__( 'Support Forum' ) . '</a>'; $links['support'] = '<a href="' . esc_url( $this->plugin_url_support ) . '" title="' . esc_attr( $this->helper->__( 'Support Forum' ) ) . '">' . $this->helper->__( 'Support Forum' ) . '</a>';
} }
return (array)$links; return (array)$links;
} }
public function basic_ordernumber_plugin_row_meta( $links, $file ) { public function basic_ordernumber_plugin_row_meta( $links, $file ) {
if ($file==$this->plugin_basename && !$this->is_advanced) { if ($file==$this->plugin_basename && !$this->is_advanced) {
$links['advanced'] = '<a href="' . esc_url( 'http://open-tools.net/woocommerce/advanced-ordernumbers-for-woocommerce.html' ) . '" title="' . esc_attr( $this->helper->__('Purchase Advanced Version')) . '">' . $this->helper->__('Purchase Advanced Version') . '</a>'; $links['advanced'] = '<a href="' . esc_url( $this->plugin_url_advanced ) . '" title="' . esc_attr( $this->helper->__('Purchase Advanced Version')) . '">' . $this->helper->__('Purchase Advanced Version') . '</a>';
} }
return (array)$links; return (array)$links;
} }
...@@ -383,7 +427,7 @@ class OpenToolsOrdernumbersBasic { ...@@ -383,7 +427,7 @@ class OpenToolsOrdernumbersBasic {
} }
function generateNumber($orderid, $order, $type='ordernumber') { function generateNumber($orderid, $order, $type='ordernumber') {
if (get_option('customize_'.$type, 'no')!='no') { if ($this->numbers_activated($type)) {
$fmt = get_option ($type.'_format', "#"); $fmt = get_option ($type.'_format', "#");
$ctrsettings = array( $ctrsettings = array(
"${type}_format" => '', "${type}_format" => '',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment