WC_Settings_Tax::save_tax_rates()
Save tax rates.
Description Description
Source Source
File: includes/admin/settings/class-wc-settings-tax.php
public function save_tax_rates() { global $wpdb; $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( $posted_countries ); // 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 ( $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 === absint( $_POST['remove_tax_rate'][ $key ] ) ) { $tax_rate_id = absint( $key ); WC_Tax::_delete_tax_rate( $tax_rate_id ); continue; } else { $tax_rate_id = absint( $key ); WC_Tax::_update_tax_rate( $tax_rate_id, $tax_rate ); } if ( isset( $_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( wp_unslash( $_POST['tax_rate_city'][ $key ] ) ) ); } } }