Tax Calculation module
Learn about the Tax Calculation module.
The TaxCalculation
module handles calculating taxes on the Shop, Product, and Cart pages and shows the final tax. This module shows taxes based on the WooCommerce backend settings.
Specifications
This module handles the tax calculation for single products and shop products. It hides the tax class (Standard, Reduce Rate, and Zero Rate) settings in WooCommerce Tax Settings.
The tax calculation is handled via the Digital River platform.
Use the customer's shipping address to render product tax rates on the Shop and Single Product page.
Hide the tax row from the Cart page to finalize the tax rate review on the Checkout page.
After all the details are on the Checkout page, click Review Order on the Drop-in UI.
The tax-exclusive or inclusive price depends on the Admin tax settings. Use those settings to display whether the tax is inclusive or exclusive of the product price on the Single product page and Shop page.
Tax Calculation Methods
Tax Calculation class
This class is the module's entry point.
Method
Args, Returns, and Descriptions
__construct
Arg: ApiInstance
$api_instance, OrderContainer
$container
Return: string
Description: Constructs the object by passing its dependencies
name
Arg: -
Return: string
Description: Returns the name of the module
init
Arg: -
Return: void
Description: Initializes the module, registers necessary hooks, and initializes [StateManager](/src/Modules/OrderManagement/StateManager.php)
calculate_tax
Arg: -
Return: bool
Description: Returns a boolean value representing if tax needs to be calculated for the current page
Tax Calculation Container class
This class acts as a Dependency Injection container for providing dependencies to classes in the OrderManagement
module.
Method
Args, Returns, and Descriptions
__construct
Arg: PimpleContainer
Return: void
Description: Accepts a Dependency Injection container as an argument and assigns it to a container attribute
define_services
Arg: -
Return: void
Description: Defines all the classes present within the module
Product class
This class relates to various products and adds a custom class to the product container and product price element.
Method
Args, Returns, and Descriptions
__construct
Arg: TaxCalculation
Return: void
Description: Accepts TaxCalculation
dependency as an argument and assigns it to the tax_handler
attribute
init
Arg: -
Return: void
Description: Registers necessary hooks
assets
Arg: -
Return: void
Description: Enqueues necessary scripts and stylesheets
product_classes
Arg: array $classes
Return: array
Description: Adds custom class to the product container
price_html
Arg: string $html, WC_Product
$obj
Return: string
Description: Filters the price HTML markup
maybe_calculate_tax
Arg: bool $calculate_tax
Return: bool
Description: If the customer is from a different country than the store, calculate taxes and return the default value for $calculate_taxes
Cart Tax Calculation class
This class handles calculating taxes on the Cart page, shows the final tax, and shows taxes based on the WooCommerce backend settings.
Method
Args, Returns, and Descriptions
init
Arg: -
Return: void
Description: Initializes the module and register necessary hooks
assets
Arg: -
Return: void
Description: Enqueues necessary scripts and stylesheets
woocommerce_cart_subtotal
Arg: float $subtotal, $compound, $cart
Return: book
Descripton: -
woocommerce_cart_contents_total
Arg: float $total
Return: float
Description: -
woocommerce_widget_cart_is_hidden
Arg: bool $is_hidden
Return: bool
Description: Creates checkout, stores it in the WooCommerce session, and returns the $is_hidden
parameter
woocommerce_cart_collaterals
Arg: -
Return: void
Description: Loads the custom template for the cart section
wc_get_template
Arg: -
Return: void
Description: Loads the custom template for the cart section if the template name is cart/cart-totals.php
woocommerce_cart_shipping_method_full_label
Arg: String $label, WC_Shipping_Rate
$method
Return: String
Description: Loads the custom template for the cart section if the template name is cart/cart-totals.php
woocommerce_cart_item_price
Arg: String $price, array $cart_item
Return: String
Description: Alters the price HTML on the Cart
page
woocommerce_cart_item_subtotal
Arg: String $subtotal, array $cart_item
Return: String
Description: Alters the price HTML on the Cart
page
prepare_cart_checkout_request
Arg: -
Return: array
Description: Prepares request data for checkout
process_cart
Arg: -
Return: Checkout
Description: Processes the cart update
request
Traits\Tax Calculation Utility trait
The TaxCalculation
class uses Utility methods.
Method
Args, Returns, and Descriptions
compare_purchase_location
Arg: PurchaseLocation
$location1, PurchaseLocation
$location2
Return: bool
Description: Compares two purchase location data and returns true
if they are identical
orfalse
compare_ship_from_addresses
Arg: ShipFrom
$ship_from1, ShipFrom
$ship_from2
Return: bool
Description: Compares two ShipFrom
addresses and returns as true
if they are identical or false
Endpoints\Product Price class
This class creates a new REST API Endpoint to fetch the product price.
Method
Args, Returns, and Descriptions
__construct
Arg: TaxCalculation
Return: void
Description: Accepts CheckoutService
and Store
dependencies as arguments and assigns them to the tax_handler
attribute
init
Arg: -
Return: void
Description: Registers necessary hooks
add_price_filters
Arg: -
Return: void
Description: Registers filters related to the price
remove_price_filters
Arg: -
Return: void
Description: Removes registered filters
register
Arg: -
Return: void
Description: Registers REST API route
set_request
Arg: mixed $result, WP_REST_Server
$server, WP_REST_Request
$request
Return: void
Description: Sets request property
fetch_price
Arg: WP_REST_Request
$request
Return: WP_REST_Response/WP_Error
Description: Callback to handle API Endpoint
dr_price
Arg: String $price, WC_Product
$product
Return: mixed
Description: Filters the price
dr_variation_prices
Arg: array $prices_array, WC_Product
$product
Return: array
Description: Filters variation prices by calculating prices via Digital River
add_shipping_choices
Arg: array $data, WC_Product
$product
Return: array
Description: Adds shipping choice element to data
add_purchase_location
Arg: array $data
Return: array
Description: Adds purchase location to tax estimate data
item
Arg: WC_Product
$product
Return: SKURequestItem
Description: Prepares a product to send in checkout request
Last updated