From 5a77e1b9d88f1fe6f0624767acc56e3b8d8e3d6c Mon Sep 17 00:00:00 2001 From: vendidero Date: Wed, 8 May 2024 14:01:54 +0200 Subject: [PATCH] Added base location filters. Version bump to 2.0.4. --- composer.json | 2 +- src/Helper.php | 54 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 5f41f80..c50a1fc 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "type": "wordpress-plugin", "license": "GPL-3.0-or-later", "prefer-stable": true, - "version": "2.0.3", + "version": "2.0.4", "minimum-stability": "dev", "require": { "automattic/jetpack-autoloader": "^2.6.0", diff --git a/src/Helper.php b/src/Helper.php index 6bf6dba..31f4305 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -15,7 +15,7 @@ class Helper { * * @var string */ - const VERSION = '2.0.3'; + const VERSION = '2.0.4'; public static function get_version() { return self::VERSION; @@ -335,10 +335,10 @@ public static function get_order_taxable_location( $order ) { $order = is_a( $order, 'WC_Order' ) ? $order : wc_get_order( $order ); $taxable_address = array( - WC()->countries->get_base_country(), - WC()->countries->get_base_state(), - WC()->countries->get_base_postcode(), - WC()->countries->get_base_city(), + self::get_base_country(), + self::get_base_state(), + self::get_base_postcode(), + self::get_base_city(), ); if ( ! $order ) { @@ -390,10 +390,10 @@ public static function get_taxable_location() { if ( $is_admin_order_request ) { $taxable_address = array( - WC()->countries->get_base_country(), - WC()->countries->get_base_state(), - WC()->countries->get_base_postcode(), - WC()->countries->get_base_city(), + self::get_base_country(), + self::get_base_state(), + self::get_base_postcode(), + self::get_base_city(), ); if ( isset( $_POST['order_id'] ) && ( $order = wc_get_order( absint( $_POST['order_id'] ) ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing @@ -543,10 +543,42 @@ public static function current_request_has_vat_exempt() { public static function get_base_country() { if ( WC()->countries ) { - return WC()->countries->get_base_country(); + $base_country = WC()->countries->get_base_country(); } else { - return wc_get_base_location()['country']; + $base_country = wc_get_base_location()['country']; } + + return apply_filters( 'woocommerce_eu_tax_helper_base_country', $base_country ); + } + + public static function get_base_postcode() { + $base_postcode = ''; + + if ( WC()->countries ) { + $base_postcode = WC()->countries->get_base_postcode(); + } + + return apply_filters( 'woocommerce_eu_tax_helper_base_postcode', $base_postcode ); + } + + public static function get_base_state() { + $base_state = ''; + + if ( WC()->countries ) { + $base_state = WC()->countries->get_base_state(); + } + + return apply_filters( 'woocommerce_eu_tax_helper_base_state', $base_state ); + } + + public static function get_base_city() { + $base_city = ''; + + if ( WC()->countries ) { + $base_city = WC()->countries->get_base_city(); + } + + return apply_filters( 'woocommerce_eu_tax_helper_base_city', $base_city ); } /**