PHP Class WC_Tax

Author: WooThemes
Afficher le fichier Open project: woocommerce/woocommerce Class Usage Examples

Méthodes publiques

Свойство Type Description
$precision integer Precision.
$round_at_subtotal boolean Round at subtotal.

Méthodes publiques

Méthode 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

Méthode 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 méthode

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 méthode

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
Résultat array

_insert_tax_rate() public static méthode

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

_update_tax_rate() public static méthode

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 méthode

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
Résultat string

_update_tax_rate_postcodes() public static méthode

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
Résultat string

calc_exclusive_tax() public static méthode

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

calc_inclusive_tax() public static méthode

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

calc_shipping_tax() public static méthode

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

calc_tax() public static méthode

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
Résultat array Array of rates + prices after tax

find_rates() public static méthode

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

find_shipping_rates() public static méthode

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

format_tax_rate_class() public static méthode

format the class.
public static format_tax_rate_class ( string $class ) : string
$class string
Résultat string

get_base_tax_rates() public static méthode

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

get_rate_code() public static méthode

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
Résultat string

get_rate_label() public static méthode

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
Résultat string

get_rate_percent() public static méthode

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
Résultat string

get_rates() public static méthode

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

get_rates_for_tax_class() public static méthode

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

get_shipping_tax_rates() public static méthode

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

get_shop_base_rate() public static méthode

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

get_tax_classes() public static méthode

Get store tax classes.
public static get_tax_classes ( ) : array
Résultat array

get_tax_location() public static méthode

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.
Résultat array

get_tax_total() public static méthode

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

init() public static méthode

Load options.
public static init ( )

is_compound() public static méthode

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

maybe_remove_tax_class_rates() public static méthode

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 méthode

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
Résultat double

Property Details

$precision public_oe static_oe property

Precision.
public static int $precision
Résultat integer

$round_at_subtotal public_oe static_oe property

Round at subtotal.
public static bool $round_at_subtotal
Résultat boolean