Function
Taxes functions
On this page
- rpress_use_taxes()
- rpress_get_tax_rates()
- rpress_get_tax_rate()
- rpress_get_formatted_tax_rate()
- rpress_calculate_tax()
- rpress_sales_tax_for_year()
- rpress_get_sales_tax_for_year()
- rpress_is_cart_taxed()
- rpress_prices_include_tax()
- rpress_prices_show_tax_on_checkout()
- rpress_cart_needs_tax_address_fields()
- rpress_fooditem_is_tax_exclusive()
- rpress_addon_is_tax_exclusive()
- rpress_get_tax_name()
- rpress_show_billing_fields()
Functions for tax settings and tax calculation.
15 functions. Each entry shows the signature, parameters, return value and where it is defined. Functions marked internal are hook callbacks, screen renderers and other plumbing that extensions normally do not call.
rpress_use_taxes()#
Checks whether taxes are enabled in the RestroPress settings.
Reads the enable_taxes option and passes the result through the rpress_use_taxes filter.
rpress_use_taxes()
Returns bool: True when taxes are enabled.
Example
if ( rpress_use_taxes() ) {
echo 'Taxes are on';
}
Defined in includes/tax-functions.php, line 25.
rpress_get_tax_rates()#
Returns the tax rates stored in the rpress_tax_rates option.
Result is filtered through rpress_get_tax_rates. The current calculation uses the single tax_rate setting, not this list.
rpress_get_tax_rates()
Returns array: Stored tax rates, empty array if none.
Defined in includes/tax-functions.php, line 35.
rpress_get_tax_rate()#
Returns the configured tax rate as a decimal fraction.
Reads the tax_rate setting and divides it by 100, so 8.5 is returned as 0.085. The value is filtered through rpress_tax_rate, which receives the country and state.
rpress_get_tax_rate( $country = false, $state = false )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$country | string|false | false | Country code passed to the rpress_tax_rate filter. Not used by the built-in calculation. |
$state | string|false | false | State code passed to the rpress_tax_rate filter. Not used by the built-in calculation. |
Returns float: Tax rate as a fraction (0.085 for 8.5%), after filtering.
Example
$rate = rpress_get_tax_rate();
$tax = 20.00 * $rate;
Defined in includes/tax-functions.php, line 47.
rpress_get_formatted_tax_rate()#
Returns the tax rate as a percentage string such as "8.5%".
Multiplies the rate from rpress_get_tax_rate() by 100, rounds to 4 decimals and appends a percent sign. Filtered through rpress_formatted_tax_rate.
rpress_get_formatted_tax_rate( $country = false, $state = false )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$country | string|false | false | Country code passed to rpress_get_tax_rate(). |
$state | string|false | false | State code passed to rpress_get_tax_rate(). |
Returns string: Formatted rate with a trailing percent sign.
Defined in includes/tax-functions.php, line 61.
rpress_calculate_tax()#
Calculates the tax for an amount using the configured rate.
Returns 0 when taxes are disabled or the amount is not positive. If $ignore_inclusive is true, tax is amount times rate, rounded down to 2 decimals. Otherwise, when prices include tax, the tax portion is extracted from the amount; when they do not, tax is added on top. Filtered through rpress_taxed_amount.
rpress_calculate_tax( $amount = 0, $country = false, $state = false ,$ignore_inclusive =false)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$amount | float|int|string | 0 | Amount to calculate tax for. |
$country | string|false | false | Country code passed to the rate filter. |
$state | string|false | false | State code passed to the rate filter. |
$ignore_inclusive | bool | false | When true, treats the amount as tax-exclusive even if prices include tax, and floors the result to 2 decimals. |
Returns float: Tax amount, 0.0 when taxes are disabled.
Example
$tax = rpress_calculate_tax( 25.00 );
echo rpress_currency_filter( rpress_format_amount( $tax ) );
Defined in includes/tax-functions.php, line 76.
rpress_sales_tax_for_year()#
Outputs the formatted total sales tax for a year.
Echoes the escaped, currency-formatted value of rpress_get_sales_tax_for_year().
rpress_sales_tax_for_year( $year = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$year | int|null | null | Four-digit year, for example 2026. |
Note: Echoes output instead of returning it.
Defined in includes/tax-functions.php, line 102.
rpress_get_sales_tax_for_year()#
Returns the total tax recorded on orders placed in a given year.
Sums the _rpress_payment_tax meta of rpress_payment posts with status publish or revoked whose post date falls in the year. Returns 0 when $year is empty. Filtered through rpress_get_sales_tax_for_year.
rpress_get_sales_tax_for_year( $year = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$year | int|null | null | Four-digit year, for example 2026. |
Returns string|int: Summed tax from the database query (numeric string), or 0 when no year is given.
Example
$tax = rpress_get_sales_tax_for_year( 2026 );
Note: Runs a direct database query on each call. The value comes back from wpdb as a string, so cast it if you need a float.
Defined in includes/tax-functions.php, line 113.
rpress_is_cart_taxed()#
Checks whether the cart is taxed.
Wrapper around rpress_use_taxes().
rpress_is_cart_taxed()
Returns bool: True when taxes are enabled.
Defined in includes/tax-functions.php, line 141.
rpress_prices_include_tax()#
Checks whether menu item prices are entered inclusive of tax.
True only when the prices_include_tax option equals 'yes' and taxes are enabled. Filtered through rpress_prices_include_tax.
rpress_prices_include_tax()
Returns bool: True when prices include tax.
Defined in includes/tax-functions.php, line 150.
rpress_prices_show_tax_on_checkout()#
Checks whether tax is displayed on prices at checkout.
True only when the checkout_include_tax option equals 'yes' and taxes are enabled. Filtered through rpress_taxes_on_prices_on_checkout.
rpress_prices_show_tax_on_checkout()
Returns bool: True when tax should be shown on checkout prices.
Defined in includes/tax-functions.php, line 160.
rpress_cart_needs_tax_address_fields()#
Checks whether address fields are needed for tax purposes.
Returns false when the cart is not taxed. Otherwise returns true as long as the rpress_after_cc_fields action has not yet run.
rpress_cart_needs_tax_address_fields()
Returns bool: True when taxes are on and the action has not fired yet.
Internal. Defined in includes/tax-functions.php, line 170.
rpress_fooditem_is_tax_exclusive()#
Checks whether a menu item is excluded from tax.
Always false by default. The only way to change the result is the rpress_fooditem_is_tax_exclusive filter, which receives the menu item ID.
rpress_fooditem_is_tax_exclusive( $fooditem_id = 0 )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$fooditem_id | int | 0 | Menu item ID passed to the filter. |
Returns bool: False unless a filter changes it.
Note: No built-in setting backs this function; it only returns what the filter supplies.
Defined in includes/tax-functions.php, line 181.
rpress_addon_is_tax_exclusive()#
Checks whether an add-on is excluded from tax.
Returns the string 'no' by default. The result can be changed through the rpress_addon_is_tax_exclusive filter, which receives the add-on ID.
rpress_addon_is_tax_exclusive( $addon_id = 0 )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$addon_id | int | 0 | Add-on ID passed to the filter. |
Returns string: 'no' unless a filter changes it.
Note: Returns the string 'no', not a boolean, so compare against 'yes'/'no' rather than truthiness.
Defined in includes/tax-functions.php, line 191.
rpress_get_tax_name()#
Returns the label used for tax, defaulting to "Estimated Tax".
Reads the tax_name setting and falls back to the translated 'Estimated Tax'. Filtered through rpress_tax_name.
rpress_get_tax_name()
Returns string: Tax label.
Defined in includes/tax-functions.php, line 201.
rpress_show_billing_fields()#
Checks whether billing detail fields should be shown.
Reads the enable_billing_fields option and passes it through the rpress_show_billing_fields filter.
rpress_show_billing_fields()
Returns bool: True when billing fields should be shown.
Defined in includes/tax-functions.php, line 215.
