Plugin Directory

Changeset 3348796


Ignore:
Timestamp:
08/22/2025 07:24:40 PM (7 months ago)
Author:
wijnbergdevelopments
Message:

Fixed tax calculation if product price is zero

Location:
tax-switch-for-woocommerce
Files:
198 added
7 edited

Legend:

Unmodified
Added
Removed
  • tax-switch-for-woocommerce/trunk/README.txt

    r3336052 r3348796  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 1.5.11
     6Stable tag: 1.5.13
    77Requires PHP: 7.2
    88License: GPL-2.0+
     
    196196* B2B Market
    197197* FiboFilters
     198* Extra Product Options & Add-Ons for WooCommerce
    198199
    199200If you encounter any compatibility issues with other plugins or themes, please let us know. Your feedback helps us improve the plugin and extend compatibility to more third-party solutions.
     
    232233
    233234== Changelog ==
     235= 1.5.13 =
     236* Fixed tax calculation if product price is zero
     237
     238= 1.5.12 =
     239* Added compatibility for Extra Product Options & Add-Ons for WooCommerce
     240* Tested WooCommerce 10.1.0
     241
    234242= 1.5.11 =
    235243* Added wp_kses_allowed_html filter to allow spans in certain contexts for price displays
    236 * Added compatibility for Entr theme [See this issue](https://github.com/Paulsky/tax-switch/issues/3)
     244* Added compatibility for Entr theme. [See this issue](https://github.com/Paulsky/tax-switch/issues/3)
    237245* Improved compatibility with GeneratePress
    238246
     
    381389== Additional Information ==
    382390
     391This plugin is fully open source. You can find the source code on [GitHub](https://github.com/Paulsky/tax-switch)
     392
    383393For more information and other WordPress plugins, visit [Wijnberg Developments](https://products.wijnberg.dev/product-category/wordpress/plugins/).
    384394
  • tax-switch-for-woocommerce/trunk/build/label/block.json

    r3336052 r3348796  
    33  "apiVersion": 3,
    44  "name": "wdevs/tax-switch-label",
    5   "version": "1.5.11",
     5  "version": "1.5.13",
    66  "title": "Tax Switch text label",
    77  "category": "woocommerce",
  • tax-switch-for-woocommerce/trunk/build/switch/block.json

    r3336052 r3348796  
    33  "apiVersion": 3,
    44  "name": "wdevs/tax-switch",
    5   "version": "1.5.11",
     5  "version": "1.5.13",
    66  "title": "Tax Switch for WooCommerce",
    77  "category": "woocommerce",
  • tax-switch-for-woocommerce/trunk/includes/class-wdevs-tax-switch-compatibility.php

    r3336052 r3348796  
    130130                wp_localize_script(
    131131                    $kapee_handle,
     132                    'wtsCompatibilityObject',
     133                    [ 'baseTaxRate' => $tax_rate ]
     134                );
     135            }
     136
     137            // Extra Product Options & Add-Ons for WooCommerce
     138            if ( $this->is_plugin_active( 'woocommerce-tm-extra-product-options/tm-woo-extra-product-options.php' ) ) {
     139                $tmtepo_handle = 'wdevs-tax-switch-woocommerce-tm-extra-product-options';
     140                $tmtepo_asset = $this->enqueue_script($tmtepo_handle, 'switch', 'woocommerce-tm-extra-product-options', [ 'themecomplete-epo' ]);
     141
     142                wp_localize_script(
     143                    $tmtepo_handle,
    132144                    'wtsCompatibilityObject',
    133145                    [ 'baseTaxRate' => $tax_rate ]
  • tax-switch-for-woocommerce/trunk/includes/class-wdevs-tax-switch.php

    r3336052 r3348796  
    296296            }
    297297
    298             // Check for YITH WooCommerce Product Add-Ons (both free and premium versions)
    299             // and for Woocommerce Quantity Manager
     298            // Check for YITH WooCommerce Product Add-Ons (both free and premium versions),
     299            // Woocommerce Quantity Manager, and Extra Product Options & Add-Ons for WooCommerce
    300300            if ( $this->is_any_plugin_active( [
    301301                'yith-woocommerce-product-add-ons/init.php',
    302302                'yith-woocommerce-advanced-product-options-premium/init.php',
    303                 'woocommerce-quantity-manager-pro/woocommerce-quantity-manager-pro.php'
     303                'woocommerce-quantity-manager-pro/woocommerce-quantity-manager-pro.php',
     304                'woocommerce-tm-extra-product-options/tm-woo-extra-product-options.php'
    304305            ] ) ) {
    305306                $this->loader->add_filter(
  • tax-switch-for-woocommerce/trunk/includes/trait-wdevs-tax-switch-helper.php

    r3300428 r3348796  
    6969        $price_excl_tax = wc_get_price_excluding_tax( $product );
    7070
    71         // Prevent division by zero
     71        // Prevent division by zero - use fallback for 0.00 products
     72        if ( $price_excl_tax <= 0 ) {
     73            return $this->get_fallback_tax_rate( $product );
     74        }
     75
     76        $price_incl_tax = wc_get_price_including_tax( $product );
     77
     78        $tax_rate = ( ( $price_incl_tax - $price_excl_tax ) / $price_excl_tax ) * 100;
     79
     80        return $tax_rate;
     81        //return round($tax_rate, 2);
     82    }
     83
     84    /**
     85     * Get fallback tax rate for products with €0.00 price
     86     * Creates a temporary product with €1.00 price to calculate tax rate
     87     *
     88     * @param WC_Product $product
     89     * @return float|int
     90     * @since 1.5.13
     91     */
     92    public function get_fallback_tax_rate( $product ) {
     93        if ( ! $product ) {
     94            return 0;
     95        }
     96
     97        // Create a temporary product clone
     98        $calculator = clone $product;
     99
     100        // Set price to 1.00 to avoid division by zero
     101        $calculator->set_price( 1.00 );
     102
     103        // Directly calculate tax rate to avoid infinite recursion
     104        $price_excl_tax = wc_get_price_excluding_tax( $calculator );
     105
     106        // Prevent division by zero (should not happen with €10.00 but safety first)
    72107        if ( $price_excl_tax <= 0 ) {
    73108            return 0;
    74109        }
    75110
    76         $price_incl_tax = wc_get_price_including_tax( $product );
     111        $price_incl_tax = wc_get_price_including_tax( $calculator );
    77112
    78113        $tax_rate = ( ( $price_incl_tax - $price_excl_tax ) / $price_excl_tax ) * 100;
    79114
    80115        return $tax_rate;
    81         //return round($tax_rate, 2);
    82116    }
    83117
  • tax-switch-for-woocommerce/trunk/wdevs-tax-switch.php

    r3336052 r3348796  
    1717 * Plugin URI:           https://wijnberg.dev
    1818 * Description:          Let customers toggle between inclusive and exclusive VAT pricing in your WooCommerce store.
    19  * Version:              1.5.11
     19 * Version:              1.5.13
    2020 * Author:               Wijnberg Developments
    2121 * Author URI:           https://wijnberg.dev/
     
    2727 * Requires at least:    5.0
    2828 * WC requires at least: 7.0.0
    29  * WC tested up to:      10.0.2
     29 * WC tested up to:      10.1.0
    3030 * Requires Plugins:     woocommerce
    3131 */
     
    4141 * Rename this for your plugin and update it as you release new versions.
    4242 */
    43 define( 'WDEVS_TAX_SWITCH_VERSION', '1.5.11' );
     43define( 'WDEVS_TAX_SWITCH_VERSION', '1.5.13' );
    4444
    4545/**
Note: See TracChangeset for help on using the changeset viewer.