diff --git a/CHANGELOG.md b/CHANGELOG.md index a0cd709..03acdf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog All notable changes to the Tax Switch for Woocommerce plugin will be documented in this file. +## [1.1.9] - 2024-11-04 +### Added +- Extra check for filtering backend and frontend AJAX requests (which adds compatibility for [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)). +### Updated +- Fixed a bug where the admin request checks failed when Wordpress is installed in a subdirectory. + ## [1.1.8] - 2024-10-25 ### Added - Compatibility for YITH WooCommerce Product Add-ons & Extra Options Premium diff --git a/README.txt b/README.txt index 10a13ed..45e78cd 100644 --- a/README.txt +++ b/README.txt @@ -3,7 +3,7 @@ Contributors: wijnbergdevelopments Tags: woocommerce, tax, vat Requires at least: 5.0 Tested up to: 6.6 -Stable tag: 1.1.8 +Stable tag: 1.1.9 Requires PHP: 7.2 License: GPL-2.0+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt @@ -77,6 +77,9 @@ You can also use this shortcode in your theme files with the do_shortcode() func Some WooCommerce Blocks are not fully compatible with this plugin as they do not use standard WooCommerce filters for price display. This is a known limitation of WooCommerce Blocks and not specific to this plugin. You can fix this by using WooCommerce shortcodes instead of the WooCommerce Blocks. == Changelog == += 1.1.9 = +* Added extra check for filtering backend and frontend AJAX requests (which adds compatibility for [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)) +* Fixed a bug where the admin request checks failed when Wordpress is installed in a subdirectory = 1.1.8 = * Added compatibility for YITH WooCommerce Product Add-ons & Extra Options Premium diff --git a/block/src/block.json b/block/src/block.json index 3813e83..346ece6 100644 --- a/block/src/block.json +++ b/block/src/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "wdevs/tax-switch", - "version": "1.1.8", + "version": "1.1.9", "title": "Tax Switch for WooCommerce", "category": "woocommerce", "icon": "money-alt", diff --git a/block/src/compatibility/ProductAddOns.js b/block/src/compatibility/ProductAddOns.js index a99ec27..44dbf2b 100644 --- a/block/src/compatibility/ProductAddOns.js +++ b/block/src/compatibility/ProductAddOns.js @@ -88,8 +88,8 @@ class ProductAddOns { } } } - vm.handlePriceUpdate(); } + vm.handlePriceUpdate(); } }, 10 ); } @@ -132,6 +132,7 @@ class ProductAddOns { handlePriceUpdate() { const elements = { + productPrice: jQuery( '#wapo-total-product-price' ), options: jQuery( '#wapo-total-options-price' ), order: jQuery( '#wapo-total-order-price' ), }; diff --git a/includes/class-wdevs-tax-switch.php b/includes/class-wdevs-tax-switch.php index 37fe6b6..d590fda 100644 --- a/includes/class-wdevs-tax-switch.php +++ b/includes/class-wdevs-tax-switch.php @@ -366,9 +366,16 @@ private function is_admin_request() { /** * Get current URL. * - * @link https://wordpress.stackexchange.com/a/126534 + * @link https://wordpress.stackexchange.com/a/237498/178511 */ - $current_url = home_url( add_query_arg( null, null ) ); + $parts = parse_url(home_url()); + $current_url = $parts['scheme'] . '://' . $parts['host']; + + if (array_key_exists('port', $parts)) { + $current_url .= ':' . $parts['port']; + } + + $current_url .= add_query_arg([]); /** * Get admin URL and referrer. @@ -389,7 +396,7 @@ private function is_admin_request() { if ( 0 === strpos( $referrer, $admin_url ) ) { return true; } else { - return ! $this->is_doing_ajax(); + return ! $this->is_frontend_ajax_request(); } } else { return false; @@ -411,4 +418,28 @@ private function is_doing_ajax() { } } + /** + * @return bool + * @since 1.1.9 + */ + private function is_frontend_ajax_request() { + + $script_filename = isset( $_SERVER['SCRIPT_FILENAME'] ) ? $_SERVER['SCRIPT_FILENAME'] : ''; + + if ( $this->is_doing_ajax() ) { + $referrer_raw = wp_get_raw_referer(); + if ( $referrer_raw === false ) { + return false; + } + + //If referer does not contain admin URL and we are using the admin-ajax.php endpoint, this is likely a frontend AJAX request + if ( ( ( strpos( $referrer_raw, admin_url() ) === false ) && ( basename( $script_filename ) === 'admin-ajax.php' ) ) ) { + return true; + } + } + + //If no checks triggered, we end up here - not an AJAX request. + return false; + } + } diff --git a/package.json b/package.json index 6ea5b81..e17b684 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wdevs-tax-switch", - "version": "1.1.8", + "version": "1.1.9", "description": "Let customers toggle between inclusive and exclusive VAT pricing in your WooCommerce store.", "author": "Wijnberg Developments", "license": "GPL-2.0-or-later", diff --git a/wdevs-tax-switch.php b/wdevs-tax-switch.php index d640aaa..360e1a2 100644 --- a/wdevs-tax-switch.php +++ b/wdevs-tax-switch.php @@ -16,7 +16,7 @@ * Plugin Name: Tax Switch for WooCommerce * Plugin URI: https://wijnberg.dev * Description: Let customers toggle between inclusive and exclusive VAT pricing in your WooCommerce store. - * Version: 1.1.8 + * Version: 1.1.9 * Author: Wijnberg Developments * Author URI: https://wijnberg.dev/ * License: GPL-2.0+ @@ -41,7 +41,7 @@ * Start at version 1.0.0 and use SemVer - https://semver.org * Rename this for your plugin and update it as you release new versions. */ -define( 'WDEVS_TAX_SWITCH_VERSION', '1.1.8' ); +define( 'WDEVS_TAX_SWITCH_VERSION', '1.1.9' ); /** * The code that runs during plugin activation.