Automattic\WooCommerce\Admin\Features\Blueprint\Importers
ImportSetWCTaxRates::add_rate()
Add a tax rate to the database.
Method of the class: ImportSetWCTaxRates{}
No Hooks.
Return
Int|false
. The tax rate ID if successfully added, false otherwise.
Usage
// protected - for code of main (parent) or child class $result = $this->add_rate( $rate );
- $rate(object) (required)
- The tax rate object.
ImportSetWCTaxRates::add_rate() ImportSetWCTaxRates::add rate code 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; }