diff --git a/includes/admin/settings/class-wc-settings-page.php b/includes/admin/settings/class-wc-settings-page.php index 468332a0d78..0ea2fc07e9b 100644 --- a/includes/admin/settings/class-wc-settings-page.php +++ b/includes/admin/settings/class-wc-settings-page.php @@ -17,11 +17,21 @@ if ( ! class_exists( 'WC_Settings_Page' ) ) : /** * WC_Settings_Page */ -class WC_Settings_Page { +abstract class WC_Settings_Page { protected $id = ''; protected $label = ''; + /** + * Constructor + */ + public function __construct() { + add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); + add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) ); + add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); + add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); + } + /** * Add this page to settings */ diff --git a/includes/admin/settings/class-wc-settings-tax.php b/includes/admin/settings/class-wc-settings-tax.php index 56c4ebb7316..c85415c5e84 100644 --- a/includes/admin/settings/class-wc-settings-tax.php +++ b/includes/admin/settings/class-wc-settings-tax.php @@ -9,7 +9,7 @@ */ if ( ! defined( 'ABSPATH' ) ) { - exit; // Exit if accessed directly + exit; } if ( ! class_exists( 'WC_Settings_Tax' ) ) : @@ -19,17 +19,14 @@ if ( ! class_exists( 'WC_Settings_Tax' ) ) : */ class WC_Settings_Tax extends WC_Settings_Page { + protected $id = 'tax'; + /** * Constructor. */ public function __construct() { - $this->id = 'tax'; $this->label = __( 'Tax', 'woocommerce' ); - - add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); - add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) ); - add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); - add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); + parent::__construct(); } /** @@ -44,12 +41,10 @@ class WC_Settings_Tax extends WC_Settings_Page { ); // Get tax classes and display as links - $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('woocommerce_tax_classes' ) ) ) ); + $tax_classes = $this->get_tax_classes(); - if ( $tax_classes ) { - foreach ( $tax_classes as $class ) { - $sections[ sanitize_title( $class ) ] = sprintf( __( '%s Rates', 'woocommerce' ), $class ); - } + foreach ( $tax_classes as $class ) { + $sections[ sanitize_title( $class ) ] = sprintf( __( '%s Rates', 'woocommerce' ), $class ); } return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections ); @@ -61,139 +56,14 @@ class WC_Settings_Tax extends WC_Settings_Page { * @return array */ public function get_settings() { - $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) ); + $tax_classes = $this->get_tax_classes(); $classes_options = array(); - if ( $tax_classes ) { - foreach ( $tax_classes as $class ) { - $classes_options[ sanitize_title( $class ) ] = esc_html( $class ); - } + + foreach ( $tax_classes as $class ) { + $classes_options[ sanitize_title( $class ) ] = esc_html( $class ); } - $settings = apply_filters('woocommerce_tax_settings', array( - - array( 'title' => __( 'Tax Options', 'woocommerce' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ), - - array( - 'title' => __( 'Enable Taxes', 'woocommerce' ), - 'desc' => __( 'Enable taxes and tax calculations', 'woocommerce' ), - 'id' => 'woocommerce_calc_taxes', - 'default' => 'no', - 'type' => 'checkbox' - ), - - array( - 'title' => __( 'Prices Entered With Tax', 'woocommerce' ), - 'id' => 'woocommerce_prices_include_tax', - 'default' => 'no', - 'type' => 'radio', - 'desc_tip' => __( 'This option is important as it will affect how you input prices. Changing it will not update existing products.', 'woocommerce' ), - 'options' => array( - 'yes' => __( 'Yes, I will enter prices inclusive of tax', 'woocommerce' ), - 'no' => __( 'No, I will enter prices exclusive of tax', 'woocommerce' ) - ), - ), - - array( - 'title' => __( 'Calculate Tax Based On:', 'woocommerce' ), - 'id' => 'woocommerce_tax_based_on', - 'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'woocommerce' ), - 'default' => 'shipping', - 'type' => 'select', - 'options' => array( - 'shipping' => __( 'Customer shipping address', 'woocommerce' ), - 'billing' => __( 'Customer billing address', 'woocommerce' ), - 'base' => __( 'Shop base address', 'woocommerce' ) - ), - ), - - array( - 'title' => __( 'Default Customer Address:', 'woocommerce' ), - 'id' => 'woocommerce_default_customer_address', - 'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'woocommerce' ), - 'default' => 'base', - 'type' => 'select', - 'options' => array( - '' => __( 'No address', 'woocommerce' ), - 'base' => __( 'Shop base address', 'woocommerce' ), - ), - ), - - array( - 'title' => __( 'Shipping Tax Class:', 'woocommerce' ), - 'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'woocommerce' ), - 'id' => 'woocommerce_shipping_tax_class', - 'css' => 'min-width:150px;', - 'default' => 'title', - 'type' => 'select', - 'options' => array( '' => __( 'Shipping tax class based on cart items', 'woocommerce' ), 'standard' => __( 'Standard', 'woocommerce' ) ) + $classes_options, - 'desc_tip' => true, - ), - - array( - 'title' => __( 'Rounding', 'woocommerce' ), - 'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'woocommerce' ), - 'id' => 'woocommerce_tax_round_at_subtotal', - 'default' => 'no', - 'type' => 'checkbox', - ), - - array( - 'title' => __( 'Additional Tax Classes', 'woocommerce' ), - 'desc' => __( 'List additional tax classes below (1 per line). This is in addition to the default Standard Rate. Tax classes can be assigned to products.', 'woocommerce' ), - 'id' => 'woocommerce_tax_classes', - 'css' => 'width:100%; height: 65px;', - 'type' => 'textarea', - 'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'woocommerce' ), PHP_EOL ) - ), - - array( - 'title' => __( 'Display prices in the shop:', 'woocommerce' ), - 'id' => 'woocommerce_tax_display_shop', - 'default' => 'excl', - 'type' => 'select', - 'options' => array( - 'incl' => __( 'Including tax', 'woocommerce' ), - 'excl' => __( 'Excluding tax', 'woocommerce' ), - ) - ), - - array( - 'title' => __( 'Price display suffix:', 'woocommerce' ), - 'id' => 'woocommerce_price_display_suffix', - 'default' => '', - 'type' => 'text', - 'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: {price_including_tax}, {price_excluding_tax}.', 'woocommerce' ), - ), - - array( - 'title' => __( 'Display prices during cart/checkout:', 'woocommerce' ), - 'id' => 'woocommerce_tax_display_cart', - 'default' => 'excl', - 'type' => 'select', - 'options' => array( - 'incl' => __( 'Including tax', 'woocommerce' ), - 'excl' => __( 'Excluding tax', 'woocommerce' ), - ), - 'autoload' => false - ), - - array( - 'title' => __( 'Display tax totals:', 'woocommerce' ), - 'id' => 'woocommerce_tax_total_display', - 'default' => 'itemized', - 'type' => 'select', - 'options' => array( - 'single' => __( 'As a single total', 'woocommerce' ), - 'itemized' => __( 'Itemized', 'woocommerce' ), - ), - 'autoload' => false - ), - - array( 'type' => 'sectionend', 'id' => 'tax_options' ), - - ) ); - - return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings ); + return apply_filters( 'woocommerce_get_settings_' . $this->id, include( 'settings-tax.php' ) ); } /** @@ -202,7 +72,7 @@ class WC_Settings_Tax extends WC_Settings_Page { public function output() { global $current_section; - $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('woocommerce_tax_classes' ) ) ) ); + $tax_classes = $this->get_tax_classes(); if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) { $this->output_tax_rates(); @@ -220,14 +90,11 @@ class WC_Settings_Tax extends WC_Settings_Page { global $current_section, $wpdb; if ( ! $current_section ) { - $settings = $this->get_settings(); WC_Admin_Settings::save_fields( $settings ); } else { - $this->save_tax_rates(); - } $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_wc_tax_rates_%')" ); @@ -242,265 +109,16 @@ class WC_Settings_Tax extends WC_Settings_Page { $page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1; $limit = 100; $current_class = $this->get_current_tax_class(); - ?> -

-

See here for available alpha-2 country codes.', 'woocommerce' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?>

- - - - - + include( 'html-settings-tax.php' ); + } - - - - - - - - - - - - - - - - - - - - get_results( $wpdb->prepare( - "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates - WHERE tax_rate_class = %s - ORDER BY tax_rate_order - LIMIT %d, %d - " , - sanitize_title( $current_class ), - ( $page - 1 ) * $limit, - $limit - ) ); - - foreach ( $rates as $rate ) { - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  [?] [?] [?] [?] [?] [?] [?] [?] [?]
- - - - - prefix}woocommerce_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) ); - - echo esc_attr( implode( '; ', $locations ) ); - ?>" placeholder="*" data-name="tax_rate_postcode[tax_rate_id ?>]" /> - - prefix}woocommerce_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) ); - echo esc_attr( implode( '; ', $locations ) ); - ?>" placeholder="*" data-name="tax_rate_city[tax_rate_id ?>]" /> - - - - - - - - tax_rate_compound, '1' ); ?> /> - - tax_rate_shipping, '1' ); ?> /> -
- - - - - - - -
- - get_tax_classes(); $current_class = ''; foreach( $tax_classes as $class ) { diff --git a/includes/admin/settings/html-settings-tax.php b/includes/admin/settings/html-settings-tax.php new file mode 100644 index 00000000000..cfdfed8d19f --- /dev/null +++ b/includes/admin/settings/html-settings-tax.php @@ -0,0 +1,262 @@ + +

+

See here for available alpha-2 country codes.', 'woocommerce' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + get_results( $wpdb->prepare( + "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates + WHERE tax_rate_class = %s + ORDER BY tax_rate_order + LIMIT %d, %d + " , + sanitize_title( $current_class ), + ( $page - 1 ) * $limit, + $limit + ) ); + + foreach ( $rates as $rate ) { + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  [?] [?] [?] [?] [?] [?] [?] [?] [?]
+ + + + + prefix}woocommerce_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) ); + + echo esc_attr( implode( '; ', $locations ) ); + ?>" placeholder="*" data-name="tax_rate_postcode[tax_rate_id ?>]" /> + + prefix}woocommerce_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) ); + echo esc_attr( implode( '; ', $locations ) ); + ?>" placeholder="*" data-name="tax_rate_city[tax_rate_id ?>]" /> + + + + + + + + tax_rate_compound, '1' ); ?> /> + + tax_rate_shipping, '1' ); ?> /> +
+ + + + + + + +
+ diff --git a/includes/admin/settings/settings-tax.php b/includes/admin/settings/settings-tax.php new file mode 100644 index 00000000000..f74e7d4826d --- /dev/null +++ b/includes/admin/settings/settings-tax.php @@ -0,0 +1,129 @@ + __( 'Tax Options', 'woocommerce' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ), + + array( + 'title' => __( 'Enable Taxes', 'woocommerce' ), + 'desc' => __( 'Enable taxes and tax calculations', 'woocommerce' ), + 'id' => 'woocommerce_calc_taxes', + 'default' => 'no', + 'type' => 'checkbox' + ), + + array( + 'title' => __( 'Prices Entered With Tax', 'woocommerce' ), + 'id' => 'woocommerce_prices_include_tax', + 'default' => 'no', + 'type' => 'radio', + 'desc_tip' => __( 'This option is important as it will affect how you input prices. Changing it will not update existing products.', 'woocommerce' ), + 'options' => array( + 'yes' => __( 'Yes, I will enter prices inclusive of tax', 'woocommerce' ), + 'no' => __( 'No, I will enter prices exclusive of tax', 'woocommerce' ) + ), + ), + + array( + 'title' => __( 'Calculate Tax Based On:', 'woocommerce' ), + 'id' => 'woocommerce_tax_based_on', + 'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'woocommerce' ), + 'default' => 'shipping', + 'type' => 'select', + 'options' => array( + 'shipping' => __( 'Customer shipping address', 'woocommerce' ), + 'billing' => __( 'Customer billing address', 'woocommerce' ), + 'base' => __( 'Shop base address', 'woocommerce' ) + ), + ), + + array( + 'title' => __( 'Default Customer Address:', 'woocommerce' ), + 'id' => 'woocommerce_default_customer_address', + 'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'woocommerce' ), + 'default' => 'base', + 'type' => 'select', + 'options' => array( + '' => __( 'No address', 'woocommerce' ), + 'base' => __( 'Shop base address', 'woocommerce' ), + ), + ), + + array( + 'title' => __( 'Shipping Tax Class:', 'woocommerce' ), + 'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'woocommerce' ), + 'id' => 'woocommerce_shipping_tax_class', + 'css' => 'min-width:150px;', + 'default' => 'title', + 'type' => 'select', + 'options' => array( '' => __( 'Shipping tax class based on cart items', 'woocommerce' ), 'standard' => __( 'Standard', 'woocommerce' ) ) + $classes_options, + 'desc_tip' => true, + ), + + array( + 'title' => __( 'Rounding', 'woocommerce' ), + 'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'woocommerce' ), + 'id' => 'woocommerce_tax_round_at_subtotal', + 'default' => 'no', + 'type' => 'checkbox', + ), + + array( + 'title' => __( 'Additional Tax Classes', 'woocommerce' ), + 'desc' => __( 'List additional tax classes below (1 per line). This is in addition to the default Standard Rate. Tax classes can be assigned to products.', 'woocommerce' ), + 'id' => 'woocommerce_tax_classes', + 'css' => 'width:100%; height: 65px;', + 'type' => 'textarea', + 'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'woocommerce' ), PHP_EOL ) + ), + + array( + 'title' => __( 'Display prices in the shop:', 'woocommerce' ), + 'id' => 'woocommerce_tax_display_shop', + 'default' => 'excl', + 'type' => 'select', + 'options' => array( + 'incl' => __( 'Including tax', 'woocommerce' ), + 'excl' => __( 'Excluding tax', 'woocommerce' ), + ) + ), + + array( + 'title' => __( 'Price display suffix:', 'woocommerce' ), + 'id' => 'woocommerce_price_display_suffix', + 'default' => '', + 'type' => 'text', + 'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: {price_including_tax}, {price_excluding_tax}.', 'woocommerce' ), + ), + + array( + 'title' => __( 'Display prices during cart/checkout:', 'woocommerce' ), + 'id' => 'woocommerce_tax_display_cart', + 'default' => 'excl', + 'type' => 'select', + 'options' => array( + 'incl' => __( 'Including tax', 'woocommerce' ), + 'excl' => __( 'Excluding tax', 'woocommerce' ), + ), + 'autoload' => false + ), + + array( + 'title' => __( 'Display tax totals:', 'woocommerce' ), + 'id' => 'woocommerce_tax_total_display', + 'default' => 'itemized', + 'type' => 'select', + 'options' => array( + 'single' => __( 'As a single total', 'woocommerce' ), + 'itemized' => __( 'Itemized', 'woocommerce' ), + ), + 'autoload' => false + ), + + array( 'type' => 'sectionend', 'id' => 'tax_options' ), + +) );