PHP Class WC_Tax

Author: WooThemes
Show file Open project: woocommerce/woocommerce Class Usage Examples

Public Properties

Property Type Description
$precision integer Precision.
$round_at_subtotal boolean Round at subtotal.

Public Methods

Method Description
_delete_tax_rate ( integer $tax_rate_id ) Delete a tax rate from the database.
_get_tax_rate ( integer $tax_rate_id, string $output_type = ARRAY_A ) : array Get tax rate.
_insert_tax_rate ( array $tax_rate ) : integer Insert a new tax rate.
_update_tax_rate ( integer $tax_rate_id, array $tax_rate ) Update a tax rate.
_update_tax_rate_cities ( integer $tax_rate_id, string $cities ) : string Update cities for a tax rate in the DB.
_update_tax_rate_postcodes ( integer $tax_rate_id, string $postcodes ) : string Update postcodes for a tax rate in the DB.
calc_exclusive_tax ( float $price, array $rates ) : array Calc tax from exclusive price.
calc_inclusive_tax ( float $price, array $rates ) : array Calc tax from inclusive price.
calc_shipping_tax ( $price, $rates ) : array Calculate the shipping tax using a passed array of rates.
calc_tax ( float $price, array $rates, boolean $price_includes_tax = false, boolean $suppress_rounding = false ) : array Calculate tax for a line.
find_rates ( array $args = [] ) : array Searches for all matching country/state/postcode tax rates.
find_shipping_rates ( array $args = [] ) : array Searches for all matching country/state/postcode tax rates.
format_tax_rate_class ( string $class ) : string format the class.
get_base_tax_rates ( $tax_class = '' ) : array Get's an array of matching rates for the shop's base country.
get_rate_code ( mixed $key_or_rate ) : string Get a rates code. Code is made up of COUNTRY-STATE-NAME-Priority. E.g GB-VAT-1, US-AL-TAX-1.
get_rate_label ( mixed $key_or_rate ) : string Return a given rates label.
get_rate_percent ( mixed $key_or_rate ) : string Return a given rates percent.
get_rates ( string $tax_class = '' ) : array Get's an array of matching rates for a tax class.
get_rates_for_tax_class ( string $tax_class ) : array | null | object Used by admin settings page.
get_shipping_tax_rates ( $tax_class = null ) : mixed Gets an array of matching shipping tax rates for a given class.
get_shop_base_rate ( $tax_class = '' ) : array Alias for get_base_tax_rates().
get_tax_classes ( ) : array Get store tax classes.
get_tax_location ( $tax_class = '' ) : array Get the customer tax location based on their status and the current page.
get_tax_total ( $taxes ) : float Round tax lines and return the sum.
init ( ) Load options.
is_compound ( $key ) : boolean Return true/false depending on if a rate is a compound rate.
maybe_remove_tax_class_rates ( string $old_value, string $value ) When the woocommerce_tax_classes option is changed, remove any orphan rates.
round ( $in ) : double Round to precision.

Private Methods

Method Description
_update_tax_rate_locations ( integer $tax_rate_id, $values, string $type ) : string Updates locations (postcode and city).
format_tax_rate ( double $rate ) : string format the rate.
format_tax_rate_city ( string $city ) : string format the city.
format_tax_rate_country ( string $country ) : string format the country.
format_tax_rate_name ( string $name ) : string format the tax rate name.
format_tax_rate_priority ( string $priority ) : integer format the priority.
format_tax_rate_state ( string $state ) : string format the state.
get_matched_tax_rates ( string $country, string $state, string $postcode, string $city, string $tax_class ) : array Loop through a set of tax rates and get the matching rates (1 per priority).
precision ( float $price ) : float Multiply cost by pow precision.
prepare_tax_rate ( array $tax_rate ) : array Prepare and format tax rate for DB insertion.
remove_precision ( float $price ) : float Divide cost by pow precision.
sort_rates ( array $rates ) : array Logical sort order for tax rates based on the following in order of priority: - Priority - County code - State code
sort_rates_callback ( $rate1, $rate2 ) Does the sort comparison.

Method Details

_delete_tax_rate() public static method

Internal use only.
Since: 2.3.0
public static _delete_tax_rate ( integer $tax_rate_id )
$tax_rate_id integer

_get_tax_rate() public static method

Internal use only.
Since: 2.5.0
public static _get_tax_rate ( integer $tax_rate_id, string $output_type = ARRAY_A ) : array
$tax_rate_id integer
$output_type string
return array

_insert_tax_rate() public static method

Internal use only.
Since: 2.3.0
public static _insert_tax_rate ( array $tax_rate ) : integer
$tax_rate array
return integer tax rate id

_update_tax_rate() public static method

Internal use only.
Since: 2.3.0
public static _update_tax_rate ( integer $tax_rate_id, array $tax_rate )
$tax_rate_id integer
$tax_rate array

_update_tax_rate_cities() public static method

Internal use only.
Since: 2.3.0
public static _update_tax_rate_cities ( integer $tax_rate_id, string $cities ) : string
$tax_rate_id integer
$cities string
return string

_update_tax_rate_postcodes() public static method

Internal use only.
Since: 2.3.0
public static _update_tax_rate_postcodes ( integer $tax_rate_id, string $postcodes ) : string
$tax_rate_id integer
$postcodes string String of postcodes separated by ; characters
return string

calc_exclusive_tax() public static method

Calc tax from exclusive price.
public static calc_exclusive_tax ( float $price, array $rates ) : array
$price float
$rates array
return array

calc_inclusive_tax() public static method

Calc tax from inclusive price.
public static calc_inclusive_tax ( float $price, array $rates ) : array
$price float
$rates array
return array

calc_shipping_tax() public static method

Calculate the shipping tax using a passed array of rates.
public static calc_shipping_tax ( $price, $rates ) : array
return array

calc_tax() public static method

Calculate tax for a line.
public static calc_tax ( float $price, array $rates, boolean $price_includes_tax = false, boolean $suppress_rounding = false ) : array
$price float Price to calc tax on
$rates array Rates to apply
$price_includes_tax boolean Whether the passed price has taxes included
$suppress_rounding boolean Whether to suppress any rounding from taking place
return array Array of rates + prices after tax

find_rates() public static method

Searches for all matching country/state/postcode tax rates.
public static find_rates ( array $args = [] ) : array
$args array
return array

find_shipping_rates() public static method

Searches for all matching country/state/postcode tax rates.
public static find_shipping_rates ( array $args = [] ) : array
$args array
return array

format_tax_rate_class() public static method

format the class.
public static format_tax_rate_class ( string $class ) : string
$class string
return string

get_base_tax_rates() public static method

Get's an array of matching rates for the shop's base country.
public static get_base_tax_rates ( $tax_class = '' ) : array
return array

get_rate_code() public static method

Get a rates code. Code is made up of COUNTRY-STATE-NAME-Priority. E.g GB-VAT-1, US-AL-TAX-1.
public static get_rate_code ( mixed $key_or_rate ) : string
$key_or_rate mixed Tax rate ID, or the db row itself in object format
return string

get_rate_label() public static method

Return a given rates label.
public static get_rate_label ( mixed $key_or_rate ) : string
$key_or_rate mixed Tax rate ID, or the db row itself in object format
return string

get_rate_percent() public static method

Return a given rates percent.
public static get_rate_percent ( mixed $key_or_rate ) : string
$key_or_rate mixed Tax rate ID, or the db row itself in object format
return string

get_rates() public static method

Get's an array of matching rates for a tax class.
public static get_rates ( string $tax_class = '' ) : array
$tax_class string
return array

get_rates_for_tax_class() public static method

Used by admin settings page.
public static get_rates_for_tax_class ( string $tax_class ) : array | null | object
$tax_class string
return array | null | object

get_shipping_tax_rates() public static method

Gets an array of matching shipping tax rates for a given class.
public static get_shipping_tax_rates ( $tax_class = null ) : mixed
return mixed

get_shop_base_rate() public static method

Alias for get_base_tax_rates().
Deprecation: 2.3
public static get_shop_base_rate ( $tax_class = '' ) : array
return array

get_tax_classes() public static method

Get store tax classes.
public static get_tax_classes ( ) : array
return array

get_tax_location() public static method

Used by get_rates(), get_shipping_rates().
public static get_tax_location ( $tax_class = '' ) : array
$tax_class string Optional, passed to the filter for advanced tax setups.
return array

get_tax_total() public static method

Round tax lines and return the sum.
public static get_tax_total ( $taxes ) : float
return float

init() public static method

Load options.
public static init ( )

is_compound() public static method

Return true/false depending on if a rate is a compound rate.
public static is_compound ( $key ) : boolean
return boolean

maybe_remove_tax_class_rates() public static method

When the woocommerce_tax_classes option is changed, remove any orphan rates.
public static maybe_remove_tax_class_rates ( string $old_value, string $value )
$old_value string
$value string

round() public static method

Filter example: to return rounding to .5 cents you'd use: function euro_5cent_rounding( $in ) { return round( $in / 5, 2 ) * 5; } add_filter( 'woocommerce_tax_round', 'euro_5cent_rounding' );
public static round ( $in ) : double
return double

Property Details

$precision public static property

Precision.
public static int $precision
return integer

$round_at_subtotal public static property

Round at subtotal.
public static bool $round_at_subtotal
return boolean