Skip to content

Commit

Permalink
v2.12.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kousikmukherjee committed Aug 28, 2024
1 parent cbeca0d commit bae92ef
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 60 deletions.
4 changes: 2 additions & 2 deletions eu-vat-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: EU/UK VAT for WooCommerce
Plugin URI: https://wpfactory.com/item/eu-vat-for-woocommerce/
Description: Manage EU VAT in WooCommerce. Beautifully.
Version: 2.12.8
Version: 2.12.9
Author: WPFactory
Author URI: https://wpfactory.com/
Text Domain: eu-vat-for-woocommerce
Expand Down Expand Up @@ -33,7 +33,7 @@ final class Alg_WC_EU_VAT {
* @var string
* @since 1.0.0
*/
public $version = '2.12.8';
public $version = '2.12.9';
public $core = null;
public $settings = array();

Expand Down
13 changes: 10 additions & 3 deletions includes/admin/class-alg-wc-eu-vat-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* EU VAT for WooCommerce - Admin Class
*
* @version 2.12.6
* @version 2.12.9
* @since 1.0.0
* @author WPFactory
*/
Expand Down Expand Up @@ -398,14 +398,21 @@ function add_meta_box() {
/**
* create_meta_box.
*
* @version 2.9.13
* @version 2.12.9
* @since 1.0.0
* @todo [dev] save actual EU VAT number used on checkout (instead of `get_post_meta( $order_id, '_' . alg_wc_eu_vat_get_field_id(), true )`)
* @todo [dev] (maybe) add country flag
*/
function create_meta_box() {
function create_meta_box( $object ) {

// remove for HPOS
/*
$order_id = get_the_ID();
$_order = wc_get_order( $order_id );
*/

$_order = is_a( $object, 'WP_Post' ) ? wc_get_order( $object->ID ) : $object;

$_customer_ip_address = ( alg_wc_eu_vat()->core->is_wc_version_below_3_0_0 ? $_order->customer_ip_address : $_order->get_customer_ip_address() );

// Country by IP
Expand Down
91 changes: 61 additions & 30 deletions includes/class-alg-wc-eu-vat-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* EU VAT for WooCommerce - Core Class
*
* @version 2.12.8
* @version 2.12.9
* @since 1.0.0
* @author WPFactory
*/
Expand Down Expand Up @@ -670,6 +670,7 @@ function set_eu_vat_country_locale_core( $country_locales, $show_in_countries, $
}
}


return $country_locales;
}

Expand Down Expand Up @@ -1140,7 +1141,7 @@ function belgium_compatibility_field_data() {
/**
* get_field_data.
*
* @version 1.7.2
* @version 2.12.9
* @since 1.3.0
* @todo [dev] rethink `$is_required` (check filters: `woocommerce_default_address_fields`, `woocommerce_billing_fields`)
* @todo [dev] (maybe) `default`
Expand All @@ -1153,38 +1154,43 @@ function get_field_data() {

$is_required = ( 'yes' === $eu_vat_required );

/*if ( '' != ( $this->required_in_countries = apply_filters( 'alg_wc_eu_vat_required_in_countries', '' ) ) ) {*/
if ( '' != $this->required_in_countries ) {
$required_eu_vat_field_countries = array_map( 'strtoupper', array_map( 'trim', explode( ',', $this->required_in_countries ) ) );
if ('yes_for_countries' === $eu_vat_required){
if ( in_array( WC()->checkout->get_value( 'billing_country' ), $required_eu_vat_field_countries ) ) {
$is_required = true;
}
}else if ('no_for_countries' === $eu_vat_required){
if ( in_array( WC()->checkout->get_value( 'billing_country' ), $required_eu_vat_field_countries ) ) {
$is_required = false;

if ( ! empty( WC()->checkout ) ) {

/*if ( '' != ( $this->required_in_countries = apply_filters( 'alg_wc_eu_vat_required_in_countries', '' ) ) ) {*/
if ( '' != $this->required_in_countries ) {
$required_eu_vat_field_countries = array_map( 'strtoupper', array_map( 'trim', explode( ',', $this->required_in_countries ) ) );
if ('yes_for_countries' === $eu_vat_required){
if ( in_array( WC()->checkout->get_value( 'billing_country' ), $required_eu_vat_field_countries ) ) {
$is_required = true;
}
}else if ('no_for_countries' === $eu_vat_required){
if ( in_array( WC()->checkout->get_value( 'billing_country' ), $required_eu_vat_field_countries ) ) {
$is_required = false;
}else{
$is_required = true;
}
}else{
$is_required = true;
if ( ! in_array( WC()->checkout->get_value( 'billing_country' ), $required_eu_vat_field_countries ) ) {
$is_required = false;
}
}
}else{
if ( ! in_array( WC()->checkout->get_value( 'billing_country' ), $required_eu_vat_field_countries ) ) {
$is_required = false;
}

if('yes_for_company' === $eu_vat_required){
if ( !empty(WC()->checkout->get_value( 'billing_company' )) ){
$is_required = true;
}
$is_required = false;
}
}

if('yes_for_company' === $eu_vat_required){
if ( !empty(WC()->checkout->get_value( 'billing_company' )) ){
$is_required = true;

if( 'yes' === get_option( 'alg_wc_eu_vat_field_let_customer_decide', 'no' ) ){
$field_id = alg_wc_eu_vat_get_field_id();
if(isset($_POST[$field_id . '_customer_decide']) && $_POST[$field_id . '_customer_decide']==1){
$is_required = false;
}
}
$is_required = false;
}

if( 'yes' === get_option( 'alg_wc_eu_vat_field_let_customer_decide', 'no' ) ){
$field_id = alg_wc_eu_vat_get_field_id();
if(isset($_POST[$field_id . '_customer_decide']) && $_POST[$field_id . '_customer_decide']==1){
$is_required = false;
}
}

return array(
Expand Down Expand Up @@ -1823,6 +1829,13 @@ function checkout_validate_vat( $_posted ) {
}
}

/**
* add_eu_vat_registration_woocommerce.
*
* @version 2.12.8
* @since 1.0.0
* @todo [dev] new field to signup form.
*/
function add_eu_vat_registration_woocommerce(){
$fields = array();
$fields[ alg_wc_eu_vat_get_field_id() ] = $this->get_field_data();
Expand All @@ -1832,6 +1845,13 @@ function add_eu_vat_registration_woocommerce(){
}
}

/**
* add_eu_vat_registration_woocommerce_validation.
*
* @version 2.12.9
* @since 1.0.0
* @todo [dev] new field to signup form.
*/
function add_eu_vat_registration_woocommerce_validation( $username, $email, $errors ){
$field_id = alg_wc_eu_vat_get_field_id();
$eu_vat_to_check = $_POST[$field_id];
Expand All @@ -1844,14 +1864,25 @@ function add_eu_vat_registration_woocommerce_validation( $username, $email, $err

if(!$is_valid){
$text_not_valid = get_option( 'alg_wc_eu_vat_progress_text_not_valid', __( 'VAT is not valid.', 'eu-vat-for-woocommerce' ) );
$errors->add( $field_id . '_error', $text_not_valid );

if( isset( $_REQUEST ) && isset( $_REQUEST['oauth_consumer_key'] ) && ! empty( $_REQUEST['oauth_consumer_key'] ) ) {

} else {
$errors->add( $field_id . '_error', $text_not_valid );
}
}
}
}

/**
* add_eu_vat_registration_save_woocommerce_field.
*
* @version 2.12.9
* @since 1.0.0
* @todo [dev] new field to signup form.
*/
function add_eu_vat_registration_save_woocommerce_field( $customer_id ) {
$field_id = alg_wc_eu_vat_get_field_id();

if ( isset( $_POST[$field_id] ) ) {
update_user_meta( $customer_id, $field_id, wc_clean( $_POST[$field_id] ) );
}
Expand Down
48 changes: 24 additions & 24 deletions langs/eu-vat-for-woocommerce.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the GNU General Public License v3.0.
msgid ""
msgstr ""
"Project-Id-Version: eu-vat-for-woocommerce 2.12.8\n"
"Project-Id-Version: eu-vat-for-woocommerce 2.12.9\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/eu-vat-for-woocommerce\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-08-01T14:31:29+02:00\n"
"POT-Creation-Date: 2024-08-28T16:49:35+02:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.9.0\n"
"X-Domain: eu-vat-for-woocommerce\n"
Expand Down Expand Up @@ -37,11 +37,11 @@ msgstr ""

#: eu-vat-for-woocommerce-blocks-initialize.php:55
#: includes/admin/class-alg-wc-eu-vat-admin.php:356
#: includes/class-alg-wc-eu-vat-core.php:1192
#: includes/class-alg-wc-eu-vat-core.php:1194
#: includes/class-alg-wc-eu-vat-core.php:1311
#: includes/class-alg-wc-eu-vat-core.php:1391
#: includes/class-alg-wc-eu-vat-core.php:1423
#: includes/class-alg-wc-eu-vat-core.php:1198
#: includes/class-alg-wc-eu-vat-core.php:1200
#: includes/class-alg-wc-eu-vat-core.php:1317
#: includes/class-alg-wc-eu-vat-core.php:1397
#: includes/class-alg-wc-eu-vat-core.php:1429
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:86
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:94
#: build/eu-vat-for-woocommerce-checkout-eu-vat-field-block.js:1
Expand Down Expand Up @@ -85,23 +85,23 @@ msgstr ""
msgid "Table is sorted by total tax value."
msgstr ""

#: includes/admin/class-alg-wc-eu-vat-admin.php:434
#: includes/admin/class-alg-wc-eu-vat-admin.php:441
msgid "Customer IP"
msgstr ""

#: includes/admin/class-alg-wc-eu-vat-admin.php:438
#: includes/admin/class-alg-wc-eu-vat-admin.php:445
msgid "Country by IP"
msgstr ""

#: includes/admin/class-alg-wc-eu-vat-admin.php:442
#: includes/admin/class-alg-wc-eu-vat-admin.php:449
msgid "Customer EU VAT Number"
msgstr ""

#: includes/admin/class-alg-wc-eu-vat-admin.php:446
#: includes/admin/class-alg-wc-eu-vat-admin.php:453
msgid "Taxes"
msgstr ""

#: includes/admin/class-alg-wc-eu-vat-admin.php:454
#: includes/admin/class-alg-wc-eu-vat-admin.php:461
msgid "Validate VAT and remove taxes"
msgstr ""

Expand Down Expand Up @@ -169,7 +169,7 @@ msgid "VAT is valid."
msgstr ""

#: includes/class-alg-wc-eu-vat-ajax.php:55
#: includes/class-alg-wc-eu-vat-core.php:1846
#: includes/class-alg-wc-eu-vat-core.php:1866
#: includes/settings/class-alg-wc-eu-vat-settings-validation.php:272
msgid "VAT is not valid."
msgstr ""
Expand Down Expand Up @@ -201,38 +201,38 @@ msgid "(optional)"
msgstr ""

#: includes/class-alg-wc-eu-vat-ajax.php:125
#: includes/class-alg-wc-eu-vat-core.php:1566
#: includes/class-alg-wc-eu-vat-core.php:1572
msgid "Error: Country by IP does not match (%s)"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:215
#: includes/class-alg-wc-eu-vat-core.php:379
#: includes/class-alg-wc-eu-vat-core.php:1741
#: includes/class-alg-wc-eu-vat-core.php:1811
#: includes/class-alg-wc-eu-vat-core.php:1747
#: includes/class-alg-wc-eu-vat-core.php:1817
#: includes/settings/class-alg-wc-eu-vat-settings-validation.php:70
msgid "<strong>EU VAT Number</strong> is not valid."
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:348
#: includes/class-alg-wc-eu-vat-core.php:1788
#: includes/class-alg-wc-eu-vat-core.php:1794
msgid "Success (checkout): VAT ID valid. Matched with prevalidated VAT numbers."
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:374
#: includes/class-alg-wc-eu-vat-core.php:1819
#: includes/class-alg-wc-eu-vat-core.php:1825
msgid "Error: VAT is not valid (checkout)"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:441
msgid "VAT SHIFTED"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:1003
#: includes/class-alg-wc-eu-vat-core.php:1004
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:163
msgid "You didn't set your VAT ID. Are you sure you want to continue?"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:1003
#: includes/class-alg-wc-eu-vat-core.php:1004
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:171
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:180
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:202
Expand All @@ -253,21 +253,21 @@ msgstr ""
msgid "Yes"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:1003
#: includes/class-alg-wc-eu-vat-core.php:1004
msgid "No"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:1115
#: includes/class-alg-wc-eu-vat-core.php:1116
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:244
msgid "I don't have a VAT ID"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:1134
#: includes/class-alg-wc-eu-vat-core.php:1135
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:260
msgid "I have a valid VAT but not exempted"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:1387
#: includes/class-alg-wc-eu-vat-core.php:1393
msgid "Customer Decide"
msgstr ""

Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: wpcodefactory, omardabbas, karzin, anbinder, algoritmika, kousikmu
Tags: EU VAT, UK VAT, tax, vat validation, VAT
Requires at least: 6.1
Tested up to: 6.6
Stable tag: 2.12.8
Stable tag: 2.12.9
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -290,6 +290,11 @@ Once activated, access the plugin's settings by navigating to “WooCommerce > S

== Changelog ==

= 2.12.9 - 28/08/2024 =
* Fix - Order metabox HPOS function support.
* Fix - Added a condition for the EU VAT field on the checkout and cart pages, restricting it from appearing on other pages where the object is not available.
* Fix - skip validation when create user through API.

= 2.12.8 - 01/08/2024 =
* Compatibility with WordPress 6.6 verified.
* Fix - alg_wc_eu_vat_parse_vat() trim vat number with ['-','.',' ']
Expand Down

0 comments on commit bae92ef

Please sign in to comment.