Skip to content

Commit

Permalink
v3.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
algoritmika committed Dec 31, 2024
1 parent fee1de6 commit 92c0286
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 46 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 Validation Manager for WooCommerce
Plugin URI: https://wpfactory.com/item/eu-vat-for-woocommerce/
Description: Manage EU VAT in WooCommerce. Beautifully.
Version: 3.2.1
Version: 3.2.2
Author: WPFactory
Author URI: https://wpfactory.com/
Text Domain: eu-vat-for-woocommerce
Expand Down Expand Up @@ -68,7 +68,7 @@ final class Alg_WC_EU_VAT {
* @var string
* @since 1.0.0
*/
public $version = '3.2.1';
public $version = '3.2.2';

/**
* core object.
Expand Down
51 changes: 35 additions & 16 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 3.1.5
* @version 3.2.2
* @since 1.0.0
*
* @author WPFactory
Expand Down Expand Up @@ -48,35 +48,41 @@ class Alg_WC_EU_VAT_Core {
* @version 3.1.5
* @since 1.0.0
*
* @todo [dev] (maybe) "eu vat number" to "eu vat"
* @todo [feature] `add_eu_vat_verify_button` (`woocommerce_form_field_text`) (`return ( alg_wc_eu_vat_get_field_id() === $key ) ? $field . '<span style="font-size:smaller !important;">' . '[<a name="billing_eu_vat_number_verify" href="">' . __( 'Verify', 'eu-vat-for-woocommerce' ) . '</a>]' . '</span>' : $field;`)
* @todo (dev) "eu vat number" to "eu vat"?
* @todo (feature) `add_eu_vat_verify_button` (`woocommerce_form_field_text`) (`return ( alg_wc_eu_vat_get_field_id() === $key ) ? $field . '<span style="font-size:smaller !important;">' . '[<a name="billing_eu_vat_number_verify" href="">' . __( 'Verify', 'eu-vat-for-woocommerce' ) . '</a>]' . '</span>' : $field;`)
*/
function __construct() {

// Properties
$this->is_wc_version_below_3_0_0 = version_compare( get_option( 'woocommerce_version', null ), '3.0.0', '<' );

// Functions
require_once( 'functions/alg-wc-eu-vat-functions-validation.php' );

// Classes
require_once( 'class-alg-wc-eu-vat-shortcode.php' );
$this->eu_vat_ajax_instance = require_once( 'class-alg-wc-eu-vat-ajax.php' );
require_once( 'admin/class-alg-wc-eu-vat-admin.php' );

// Hooks: Session, exclusion, validation
add_action( 'init', array( $this, 'start_session' ) );
add_filter( 'init', array( $this, 'maybe_exclude_vat' ), PHP_INT_MAX );

add_filter( 'woocommerce_checkout_update_order_review', array( $this, 'maybe_exclude_vat' ), PHP_INT_MAX );
add_action('woocommerce_before_calculate_totals', array( $this, 'maybe_exclude_vat' ), 99);
add_action('woocommerce_before_checkout_billing_form', array( $this, 'maybe_exclude_vat' ), PHP_INT_MAX);
add_action( 'woocommerce_before_calculate_totals', array( $this, 'maybe_exclude_vat' ), 99);
add_action( 'woocommerce_before_checkout_billing_form', array( $this, 'maybe_exclude_vat' ), PHP_INT_MAX);

add_action( 'woocommerce_after_checkout_validation', array( $this, 'checkout_validate_vat' ), PHP_INT_MAX );

// Hooks: Customer meta, default value
add_filter( 'woocommerce_customer_meta_fields', array( $this, 'add_eu_vat_number_customer_meta_field' ) );
add_filter( 'default_checkout_' . alg_wc_eu_vat_get_field_id(), array( $this, 'add_default_checkout_billing_eu_vat_number' ), PHP_INT_MAX, 2 );

// Hooks: Frontend
if ( 'yes' !== get_option( 'alg_wc_eu_vat_hide_eu_vat', 'no' ) ) {
add_filter( 'woocommerce_checkout_fields', array( $this, 'add_eu_vat_checkout_field_to_frontend' ), 99 );
}

// Hooks: Display
$positions = get_option( 'alg_wc_eu_vat_display_position', array( 'after_order_table' ) );
if ( empty( $positions ) ) {
Expand All @@ -98,10 +104,12 @@ function __construct() {
add_filter( 'woocommerce_address_to_edit', array( $this, 'add_eu_vat_number_to_editable_fields' ), PHP_INT_MAX, 2 );
add_action( 'woocommerce_customer_save_address', array( $this, 'save_eu_vat_number_from_editable_fields' ), PHP_INT_MAX, 2 );
}

// Show zero VAT
if ( 'yes' === get_option( 'alg_wc_eu_vat_always_show_zero_vat', 'no' ) ) {
add_filter( 'woocommerce_cart_tax_totals', array( $this, 'always_show_zero_vat' ), PHP_INT_MAX, 2 );
}

// Shortcodes
add_shortcode( 'alg_wc_eu_vat_translate', array( $this, 'language_shortcode' ) );

Expand Down Expand Up @@ -392,20 +400,28 @@ function init_hooks() {
/**
* add_frontend_edit_billing_fields.
*
* @version 2.12.14
* @version 3.2.2
* @since 2.12.14
*/
function add_frontend_edit_billing_fields( $fields ) {

$user_roles = apply_filters( 'alg_wc_eu_vat_show_for_user_roles', array() );
if (
! empty( $user_roles ) &&
! $this->check_current_user_roles( $user_roles )
) {
return $fields;
}

$field_id = alg_wc_eu_vat_get_field_id();

$fields[$field_id] = array(
$fields[ $field_id ] = array(
'label' => do_shortcode( get_option( 'alg_wc_eu_vat_field_label', __( 'EU VAT Number', 'eu-vat-for-woocommerce' ) ) ),
'placeholder' => do_shortcode( get_option( 'alg_wc_eu_vat_field_placeholder', __( 'EU VAT Number', 'eu-vat-for-woocommerce' ) ) ),
'required' => false,
'clear' => false,
'type' => 'text',
'class' => array('alg-wc-frontend-billing-edit'),
'class' => array( 'alg-wc-frontend-billing-edit' ),
'priority' => get_option( 'alg_wc_eu_vat_field_priority', 200 ),
);

Expand Down Expand Up @@ -1504,25 +1520,28 @@ function is_tax_status_none(){
*/
function add_eu_vat_checkout_field_to_frontend( $fields ) {

if( 'yes' === get_option( 'alg_wc_eu_vat_field_hide_tax_status_none', 'no' ) ){
if($this->is_tax_status_none()){
if ( 'yes' === get_option( 'alg_wc_eu_vat_field_hide_tax_status_none', 'no' ) ) {
if ( $this->is_tax_status_none() ) {
return $fields;
}
}

$user_roles = apply_filters( 'alg_wc_eu_vat_show_for_user_roles', array() );
if ( ! empty( $user_roles ) && ! $this->check_current_user_roles( $user_roles ) ) {
if (
! empty( $user_roles ) &&
! $this->check_current_user_roles( $user_roles )
) {
return $fields;
}
$is_required = ( 'yes' === get_option( 'alg_wc_eu_vat_field_required', 'no' ) );

if( $is_required && 'yes' === get_option( 'alg_wc_eu_vat_field_let_customer_decide', 'no' ) ){
$is_required = ( 'yes' === get_option( 'alg_wc_eu_vat_field_required', 'no' ) );
if ( $is_required && 'yes' === get_option( 'alg_wc_eu_vat_field_let_customer_decide', 'no' ) ) {
$fields['billing'][ alg_wc_eu_vat_get_field_id() . '_customer_decide' ] = $this->get_customer_decide_field_data();
}


$fields['billing'][ alg_wc_eu_vat_get_field_id() ] = $this->get_field_data();
if( 'yes' === get_option( 'alg_wc_eu_vat_belgium_compatibility', 'no' ) ){

if ( 'yes' === get_option( 'alg_wc_eu_vat_belgium_compatibility', 'no' ) ) {
$fields['billing'][ alg_wc_eu_vat_get_field_id() . '_belgium_compatibility' ] = $this->belgium_compatibility_field_data();
}

Expand Down Expand Up @@ -1715,7 +1734,7 @@ function handle_user_roles( $role ) {
* @version 1.7.0
* @since 1.7.0
*
* @todo [dev] (maybe) assign `array( 'guest' )` if `wp_get_current_user()` does not exist
* @todo (dev) assign `array( 'guest' )` if `wp_get_current_user()` does not exist?
*/
function check_current_user_roles( $user_roles_to_check ) {
if ( ! empty( $user_roles_to_check ) ) {
Expand Down
54 changes: 27 additions & 27 deletions langs/eu-vat-for-woocommerce.pot
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#: eu-vat-for-woocommerce-blocks-initialize.php:74
#: includes/admin/class-alg-wc-eu-vat-admin.php:356
#: includes/class-alg-wc-eu-vat-core.php:403
#: includes/class-alg-wc-eu-vat-core.php:404
#: includes/class-alg-wc-eu-vat-core.php:1424
#: includes/class-alg-wc-eu-vat-core.php:1426
#: includes/class-alg-wc-eu-vat-core.php:1540
#: includes/class-alg-wc-eu-vat-core.php:1617
#: includes/class-alg-wc-eu-vat-core.php:1649
#: includes/class-alg-wc-eu-vat-core.php:419
#: includes/class-alg-wc-eu-vat-core.php:420
#: includes/class-alg-wc-eu-vat-core.php:1440
#: includes/class-alg-wc-eu-vat-core.php:1442
#: includes/class-alg-wc-eu-vat-core.php:1559
#: includes/class-alg-wc-eu-vat-core.php:1636
#: includes/class-alg-wc-eu-vat-core.php:1668
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:69
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:76
msgid "EU VAT Number"
Expand Down Expand Up @@ -196,7 +196,7 @@ msgid "VAT is valid."
msgstr ""

#: includes/class-alg-wc-eu-vat-ajax.php:59
#: includes/class-alg-wc-eu-vat-core.php:2125
#: includes/class-alg-wc-eu-vat-core.php:2144
#: includes/settings/class-alg-wc-eu-vat-settings-validation.php:269
msgid "VAT is not valid."
msgstr ""
Expand All @@ -216,7 +216,7 @@ msgid "Different shipping & billing countries."
msgstr ""

#: includes/class-alg-wc-eu-vat-ajax.php:63
#: includes/class-alg-wc-eu-vat-core.php:2061
#: includes/class-alg-wc-eu-vat-core.php:2080
msgid " VAT is valid, but registered to %company_name%."
msgstr ""

Expand All @@ -231,40 +231,40 @@ msgid "(optional)"
msgstr ""

#: includes/class-alg-wc-eu-vat-ajax.php:140
#: includes/class-alg-wc-eu-vat-core.php:1794
#: includes/class-alg-wc-eu-vat-core.php:1813
#, php-format
msgid "Error: Country by IP does not match (%s)"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:454
#: includes/class-alg-wc-eu-vat-core.php:618
#: includes/class-alg-wc-eu-vat-core.php:1978
#: includes/class-alg-wc-eu-vat-core.php:2074
#: includes/class-alg-wc-eu-vat-core.php:470
#: includes/class-alg-wc-eu-vat-core.php:634
#: includes/class-alg-wc-eu-vat-core.php:1997
#: includes/class-alg-wc-eu-vat-core.php:2093
#: 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:587
#: includes/class-alg-wc-eu-vat-core.php:2027
#: includes/class-alg-wc-eu-vat-core.php:603
#: includes/class-alg-wc-eu-vat-core.php:2046
msgid ""
"Success (checkout): VAT ID valid. Matched with prevalidated VAT numbers."
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:613
#: includes/class-alg-wc-eu-vat-core.php:2082
#: includes/class-alg-wc-eu-vat-core.php:629
#: includes/class-alg-wc-eu-vat-core.php:2101
msgid "Error: VAT is not valid (checkout)"
msgstr ""

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

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

#: includes/class-alg-wc-eu-vat-core.php:1225
#: includes/class-alg-wc-eu-vat-core.php:1241
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:136
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:144
#: includes/settings/class-alg-wc-eu-vat-settings-general.php:164
Expand All @@ -286,29 +286,29 @@ msgstr ""
msgid "Yes"
msgstr ""

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

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

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

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

#: includes/class-alg-wc-eu-vat-core.php:2162
#: includes/class-alg-wc-eu-vat-core.php:2181
msgid "Keep VAT for this product"
msgstr ""

#: includes/class-alg-wc-eu-vat-core.php:2163
#: includes/class-alg-wc-eu-vat-core.php:2182
msgid ""
"Enable this to ensure VAT is charged on this product, even if the customer "
"provides a valid VAT number."
Expand Down
5 changes: 4 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.7
Stable tag: 3.2.1
Stable tag: 3.2.2
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,9 @@ Once activated, access the plugin's settings by navigating to the “WPFactory

== Changelog ==

= 3.2.2 - 31/12/2024 =
* Fix - Show field for selected user roles only.

= 3.2.1 - 29/12/2024 =
* Dev - Code refactoring and cleanup.

Expand Down

0 comments on commit 92c0286

Please sign in to comment.