Viewing 1 replies (of 1 total)
  • Plugin Author wijnbergdevelopments

    (@wijnbergdevelopments)

    Hello Chrisce,

    Thank you for your message. That is a great question. The function is used to get the opposite (‘alternate’) product price (including -> excluding OR excluding -> including). We think it’s best to avoid the tax calculation ourselfs. We create a temporary product to handle tax calculations properly. Since WooCommerce’s tax system is quite complex (dealing with different rates, locations, etc.), we let WooCommerce calculate the taxes. WooCommerce doesn’t have simple helper functions we can call/use to get the ‘opposite‘ tax.

    The calculate_alternate_price function creates this temporary product (object) to tap into WooCommerce’s built-in tax logic. We than setting the opposite store tax settings to get the alternate price. It’s considering things like:

    • Tax rates and classes
    • Store location settings
    • Customer location
    • Product tax status

    Also, this is more ‘future updates WooCommerce proof’ in our opinion.

    Don’t worry – the temporary product is just for calculations and is never saved to the database!!! It’s just a programming object in that function. That’s also why we use unset($calculator) at the end to clean things up.

    Does this make things a little more clear? Do you have (another) sugesstion? Maybe we should rename ‘alternate’ to ‘opposite’.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.