Automattic\WooCommerce\Admin\Features\Blueprint\Importers

ImportSetWCTaxRates::add_rate()protectedWC 1.0

Add a tax rate to the database.

Метод класса: ImportSetWCTaxRates{}

Хуков нет.

Возвращает

int|false. The tax rate ID if successfully added, false otherwise.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->add_rate( $rate );
$rate(объект) (обязательный)
The tax rate object.

Код ImportSetWCTaxRates::add_rate() WC 9.7.1

protected function add_rate( $rate ) {
	$tax_rate = (array) $rate;

	if ( $this->exist( $tax_rate['tax_rate_id'] ) ) {
		$this->result->add_info( "Tax rate with I.D {$tax_rate['tax_rate_id']} already exists. Skipped creating it." );
		return false;
	}

	$tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate );

	if ( isset( $rate->postcode ) ) {
		$postcode = array_map( 'wc_clean', explode( ';', $rate->postcode ) );
		$postcode = array_map( 'wc_normalize_postcode', $postcode );
		WC_Tax::_update_tax_rate_postcodes( $tax_rate_id, $postcode );
	}
	if ( isset( $rate->city ) ) {
		$cities = explode( ';', $rate->city );
		WC_Tax::_update_tax_rate_cities( $tax_rate_id, array_map( 'wc_clean', array_map( 'wp_unslash', $cities ) ) );
	}

	return $tax_rate_id;
}