phpcs
This commit is contained in:
parent
8ead48fc64
commit
0908bc0b13
|
@ -12,7 +12,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WC_Settings_Tax', false ) ) :
|
||||
if ( class_exists( 'WC_Settings_Tax', false ) ) {
|
||||
return new WC_Settings_Tax();
|
||||
}
|
||||
|
||||
/**
|
||||
* WC_Settings_Tax.
|
||||
|
@ -23,7 +25,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'tax';
|
||||
$this->id = 'tax';
|
||||
$this->label = __( 'Tax', 'woocommerce' );
|
||||
|
||||
parent::__construct();
|
||||
|
@ -32,8 +34,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
/**
|
||||
* Add this page to settings.
|
||||
*
|
||||
* @param array $pages
|
||||
*
|
||||
* @param array $pages Existing pages.
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function add_settings_page( $pages ) {
|
||||
|
@ -55,7 +56,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
'standard' => __( 'Standard rates', 'woocommerce' ),
|
||||
);
|
||||
|
||||
// Get tax classes and display as links
|
||||
// Get tax classes and display as links.
|
||||
$tax_classes = WC_Tax::get_tax_classes();
|
||||
|
||||
foreach ( $tax_classes as $class ) {
|
||||
|
@ -68,15 +69,15 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
/**
|
||||
* Get settings array.
|
||||
*
|
||||
* @param string $current_section
|
||||
* @param string $current_section Current section being shown.
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings( $current_section = '' ) {
|
||||
$settings = array();
|
||||
|
||||
if ( '' === $current_section ) {
|
||||
$settings = include( 'views/settings-tax.php' );
|
||||
}
|
||||
$settings = include( 'views/settings-tax.php' );
|
||||
}
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
|
||||
}
|
||||
|
||||
|
@ -88,7 +89,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
|
||||
$tax_classes = WC_Tax::get_tax_class_slugs();
|
||||
|
||||
if ( 'standard' === $current_section || in_array( $current_section, $tax_classes ) ) {
|
||||
if ( 'standard' === $current_section || in_array( $current_section, $tax_classes, true ) ) {
|
||||
$this->output_tax_rates();
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
@ -192,6 +193,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
|
||||
/**
|
||||
* Get tax class being edited.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function get_current_tax_class() {
|
||||
|
@ -201,7 +203,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
$current_class = '';
|
||||
|
||||
foreach ( $tax_classes as $class ) {
|
||||
if ( sanitize_title( $class ) == $current_section ) {
|
||||
if ( sanitize_title( $class ) === $current_section ) {
|
||||
$current_class = $class;
|
||||
}
|
||||
}
|
||||
|
@ -211,9 +213,10 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
|
||||
/**
|
||||
* Get a posted tax rate.
|
||||
* @param string $key Key of tax rate in the post data array
|
||||
* @param int $order Position/order of rate
|
||||
* @param string $class Tax class for rate
|
||||
*
|
||||
* @param string $key Key of tax rate in the post data array.
|
||||
* @param int $order Position/order of rate.
|
||||
* @param string $class Tax class for rate.
|
||||
* @return array
|
||||
*/
|
||||
private function get_posted_tax_rate( $key, $order, $class ) {
|
||||
|
@ -227,8 +230,8 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
);
|
||||
|
||||
foreach ( $tax_rate_keys as $tax_rate_key ) {
|
||||
if ( isset( $_POST[ $tax_rate_key ] ) && isset( $_POST[ $tax_rate_key ][ $key ] ) ) {
|
||||
$tax_rate[ $tax_rate_key ] = wc_clean( $_POST[ $tax_rate_key ][ $key ] );
|
||||
if ( isset( $_POST[ $tax_rate_key ], $_POST[ $tax_rate_key ][ $key ] ) ) {
|
||||
$tax_rate[ $tax_rate_key ] = wc_clean( wp_unslash( $_POST[ $tax_rate_key ][ $key ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,24 +249,25 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
public function save_tax_rates() {
|
||||
global $wpdb;
|
||||
|
||||
$current_class = sanitize_title( $this->get_current_tax_class() );
|
||||
$current_class = sanitize_title( $this->get_current_tax_class() );
|
||||
$posted_countries = wc_clean( wp_unslash( $_POST['tax_rate_country'] ) );
|
||||
|
||||
// get the tax rate id of the first submited row
|
||||
$first_tax_rate_id = key( $_POST['tax_rate_country'] );
|
||||
// get the tax rate id of the first submited row.
|
||||
$first_tax_rate_id = key( $posted_countries );
|
||||
|
||||
// get the order position of the first tax rate id
|
||||
// get the order position of the first tax rate id.
|
||||
$tax_rate_order = absint( $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_order FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $first_tax_rate_id ) ) );
|
||||
|
||||
$index = isset( $tax_rate_order ) ? $tax_rate_order : 0;
|
||||
|
||||
// Loop posted fields
|
||||
foreach ( $_POST['tax_rate_country'] as $key => $value ) {
|
||||
// Loop posted fields.
|
||||
foreach ( $posted_countries as $key => $value ) {
|
||||
$mode = ( 0 === strpos( $key, 'new-' ) ) ? 'insert' : 'update';
|
||||
$tax_rate = $this->get_posted_tax_rate( $key, $index ++, $current_class );
|
||||
|
||||
if ( 'insert' === $mode ) {
|
||||
$tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate );
|
||||
} elseif ( 1 == $_POST['remove_tax_rate'][ $key ] ) {
|
||||
} elseif ( 1 === absint( $_POST['remove_tax_rate'][ $key ] ) ) {
|
||||
$tax_rate_id = absint( $key );
|
||||
WC_Tax::_delete_tax_rate( $tax_rate_id );
|
||||
continue;
|
||||
|
@ -273,15 +277,13 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
}
|
||||
|
||||
if ( isset( $_POST['tax_rate_postcode'][ $key ] ) ) {
|
||||
WC_Tax::_update_tax_rate_postcodes( $tax_rate_id, wc_clean( $_POST['tax_rate_postcode'][ $key ] ) );
|
||||
WC_Tax::_update_tax_rate_postcodes( $tax_rate_id, wc_clean( wp_unslash( $_POST['tax_rate_postcode'][ $key ] ) ) );
|
||||
}
|
||||
if ( isset( $_POST['tax_rate_city'][ $key ] ) ) {
|
||||
WC_Tax::_update_tax_rate_cities( $tax_rate_id, wc_clean( $_POST['tax_rate_city'][ $key ] ) );
|
||||
WC_Tax::_update_tax_rate_cities( $tax_rate_id, wc_clean( wp_unslash( $_POST['tax_rate_city'][ $key ] ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WC_Settings_Tax();
|
||||
|
|
Loading…
Reference in New Issue