WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_AJAX::tax_rates_save_changes() public WC 1.0

Handle submissions from assets/js/settings-views-html-settings-tax.js Backbone model.

{} Это метод класса: WC_AJAX{}

Хуков нет.

Возвращает

Null. Ничего.

Использование

$result = WC_AJAX::tax_rates_save_changes();

Код WC_AJAX::tax_rates_save_changes() WC 4.7.0

<?php
public static function tax_rates_save_changes() {
	// phpcs:disable WordPress.Security.NonceVerification.Missing
	if ( ! isset( $_POST['wc_tax_nonce'], $_POST['changes'] ) ) {
		wp_send_json_error( 'missing_fields' );
		wp_die();
	}

	$current_class = ! empty( $_POST['current_class'] ) ? wp_unslash( $_POST['current_class'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

	if ( ! wp_verify_nonce( wp_unslash( $_POST['wc_tax_nonce'] ), 'wc_tax_nonce-class:' . $current_class ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
		wp_send_json_error( 'bad_nonce' );
		wp_die();
	}

	$current_class = WC_Tax::format_tax_rate_class( $current_class );

	// Check User Caps.
	if ( ! current_user_can( 'manage_woocommerce' ) ) {
		wp_send_json_error( 'missing_capabilities' );
		wp_die();
	}

	$changes = wp_unslash( $_POST['changes'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
	foreach ( $changes as $tax_rate_id => $data ) {
		if ( isset( $data['deleted'] ) ) {
			if ( isset( $data['newRow'] ) ) {
				// So the user added and deleted a new row.
				// That's fine, it's not in the database anyways. NEXT!
				continue;
			}
			WC_Tax::_delete_tax_rate( $tax_rate_id );
		}

		$tax_rate = array_intersect_key(
			$data,
			array(
				'tax_rate_country'  => 1,
				'tax_rate_state'    => 1,
				'tax_rate'          => 1,
				'tax_rate_name'     => 1,
				'tax_rate_priority' => 1,
				'tax_rate_compound' => 1,
				'tax_rate_shipping' => 1,
				'tax_rate_order'    => 1,
			)
		);

		if ( isset( $tax_rate['tax_rate'] ) ) {
			$tax_rate['tax_rate'] = wc_format_decimal( $tax_rate['tax_rate'] );
		}

		if ( isset( $data['newRow'] ) ) {
			$tax_rate['tax_rate_class'] = $current_class;
			$tax_rate_id                = WC_Tax::_insert_tax_rate( $tax_rate );
		} elseif ( ! empty( $tax_rate ) ) {
			WC_Tax::_update_tax_rate( $tax_rate_id, $tax_rate );
		}

		if ( isset( $data['postcode'] ) ) {
			$postcode = array_map( 'wc_clean', $data['postcode'] );
			$postcode = array_map( 'wc_normalize_postcode', $postcode );
			WC_Tax::_update_tax_rate_postcodes( $tax_rate_id, $postcode );
		}
		if ( isset( $data['city'] ) ) {
			WC_Tax::_update_tax_rate_cities( $tax_rate_id, array_map( 'wc_clean', array_map( 'wp_unslash', $data['city'] ) ) );
		}
	}

	WC_Cache_Helper::invalidate_cache_group( 'taxes' );
	WC_Cache_Helper::get_transient_version( 'shipping', true );

	wp_send_json_success(
		array(
			'rates' => WC_Tax::get_rates_for_tax_class( $current_class ),
		)
	);
	// phpcs:enable
}