Skip to content

Commit 39fe842

Browse files
author
Woo
committed
Updates to 2.9.3
1 parent 9f2a98b commit 39fe842

File tree

6 files changed

+191
-43
lines changed

6 files changed

+191
-43
lines changed

assets/js/admin.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
( function( $ ) {
2-
$(document.body).on( 'order-totals-recalculate-before', function( e, data ) {
3-
if( data && $( '#_billing_vat_number' ).length ) {
4-
data._billing_vat_number = $( '#_billing_vat_number' ).val();
5-
data._billing_country = $( '#_billing_country' ).val();
6-
data._shipping_country = $( '#_shipping_country' ).val();
7-
data._billing_postcode = $( '#_billing_postcode' ).val();
1+
/* global wc_eu_vat_admin_params */
2+
( function ( $ ) {
3+
$( document.body ).on(
4+
'order-totals-recalculate-before',
5+
function ( e, data ) {
6+
if ( data && $( '#_billing_vat_number' ).length ) {
7+
data._billing_vat_number = $( '#_billing_vat_number' ).val();
8+
data._billing_country = $( '#_billing_country' ).val();
9+
data._shipping_country = $( '#_shipping_country' ).val();
10+
data._billing_postcode = $( '#_billing_postcode' ).val();
11+
}
812
}
9-
});
10-
}( jQuery ) );
13+
);
14+
} )( jQuery );
15+
16+
( function ( $ ) {
17+
$( '.wc-eu-vat-block-checkout-notice' ).on(
18+
'click',
19+
'.notice-dismiss',
20+
function () {
21+
$.ajax( {
22+
url: wc_eu_vat_admin_params.ajax_url,
23+
type: 'POST',
24+
data: {
25+
action: 'wc_eu_vat_dismiss_checkout_notice',
26+
security: wc_eu_vat_admin_params.dismiss_nonce,
27+
},
28+
} );
29+
}
30+
);
31+
} )( jQuery );

assets/js/admin.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
*** EU VAT Number Changelog ***
22

3+
2024-04-22 - version 2.9.3
4+
* Add - Show an admin notice letting users know to adjust the position of the VAT number field in the Checkout Block.
5+
* Dev - Bump WooCommerce "tested up to" version 8.8.
6+
* Dev - Bump WooCommerce minimum supported version to 8.6.
7+
38
2024-03-18 - version 2.9.2
49
* Add - Option to disable Express Pay buttons for B2B stores (WooPayments compatibility).
510
* Add - Document WooPayments compatibility.

includes/class-wc-eu-vat-admin.php

Lines changed: 117 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public static function init() {
4242
add_action( 'admin_notices', array( __CLASS__, 'maybe_show_admin_notice' ) );
4343
add_action( 'update_option_woocommerce_default_country', array( __CLASS__, 'reset_admin_notice_display' ), 10, 3 );
4444
add_action( 'update_option_woocommerce_store_postcode', array( __CLASS__, 'reset_admin_notice_display' ), 10, 3 );
45+
46+
// Notice for adjust vat number field on Block checkout.
47+
add_action( 'wp_ajax_wc_eu_vat_dismiss_checkout_notice', array( __CLASS__, 'dismiss_block_checkout_notice' ), 10 );
48+
add_action( 'admin_notices', array( __CLASS__, 'maybe_show_admin_notice_for_block_checkout' ) );
4549
}
4650

4751
/**
@@ -101,11 +105,17 @@ public static function styles_and_scripts( $hook ) {
101105
// Load admin style.
102106
wp_enqueue_style( 'wc_eu_vat_admin_css', plugins_url( 'assets/css/admin.css', WC_EU_VAT_FILE ), array(), WC_EU_VAT_VERSION );
103107

104-
// Load script only on add/edit order page.
105-
if ( $is_order_edit_screen ) {
106-
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
107-
wp_enqueue_script( 'wc-eu-vat-admin', WC_EU_VAT_PLUGIN_URL . '/assets/js/admin' . $suffix . '.js', array( 'jquery' ), WC_EU_VAT_VERSION, true );
108-
}
108+
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
109+
wp_enqueue_script( 'wc-eu-vat-admin', WC_EU_VAT_PLUGIN_URL . '/assets/js/admin' . $suffix . '.js', array( 'jquery' ), WC_EU_VAT_VERSION, true );
110+
111+
wp_localize_script(
112+
'wc-eu-vat-admin',
113+
'wc_eu_vat_admin_params',
114+
array(
115+
'ajax_url' => admin_url( 'admin-ajax.php' ),
116+
'dismiss_nonce' => wp_create_nonce( 'dismiss_block_checkout_notice' ),
117+
)
118+
);
109119
}
110120

111121
/**
@@ -513,6 +523,108 @@ public static function dismiss_eu_vat_disclaimer() {
513523
public static function reset_admin_notice_display( $old_value, $value, $option ) {
514524
delete_option( 'woocommerce_eu_vat_number_dismiss_disclaimer' );
515525
}
526+
527+
/**
528+
* Display admin notice for block checkout.
529+
*
530+
* @since 2.9.3
531+
*/
532+
public static function maybe_show_admin_notice_for_block_checkout() {
533+
// Check whether disclaimer is already dismissed or taxes are not enabled.
534+
if (
535+
! wc_tax_enabled() ||
536+
'yes' === get_option( 'woocommerce_eu_vat_number_dismiss_block_checkout_notice', 'no' ) ||
537+
! current_user_can( 'manage_woocommerce' ) // phpcs:ignore WordPress.WP.Capabilities.Unknown
538+
) {
539+
return;
540+
}
541+
542+
// Check if the block checkout is the default checkout.
543+
if ( ! WC_Blocks_Utils::has_block_in_page( wc_get_page_id( 'checkout' ), 'woocommerce/checkout' ) ) {
544+
return;
545+
}
546+
547+
// Check if it is already adjusted.
548+
if ( self::is_eu_vat_block_adjusted() ) {
549+
update_option( 'woocommerce_eu_vat_number_dismiss_block_checkout_notice', 'yes', false );
550+
return;
551+
}
552+
?>
553+
554+
<div class="notice notice-info wc-eu-vat-block-checkout-notice is-dismissible">
555+
<p>
556+
<?php
557+
// translators: %1$s Opening strong tag, %2$s Closing strong tag.
558+
echo wp_kses_post(
559+
sprintf(
560+
/* translators: %1$s - <strong>, %2$s - </strong>, %3$s - Link to edit checkout page, %4$s - closing tag */
561+
esc_html__( '%1$sWooCommerce EU VAT Number%2$s plugin adds a VAT number field to the checkout block though it may appear after the "Place Order" button. Please %3$sedit%4$s the checkout block to adjust the position of the VAT Number field accordingly.', 'woocommerce-eu-vat-number' ),
562+
'<strong>',
563+
'</strong>',
564+
'<a href="' . esc_url( get_edit_post_link( wc_get_page_id( 'checkout' ) ) ) . '">',
565+
'</a>'
566+
)
567+
);
568+
?>
569+
</p>
570+
</div>
571+
<?php
572+
}
573+
574+
/**
575+
* Dismiss Block checkout notice.
576+
*
577+
* @since 2.9.3
578+
*/
579+
public static function dismiss_block_checkout_notice() {
580+
check_ajax_referer( 'dismiss_block_checkout_notice', 'security' );
581+
582+
if ( ! current_user_can( 'manage_woocommerce' ) ) { // phpcs:ignore WordPress.WP.Capabilities.Unknown
583+
return;
584+
}
585+
586+
update_option( 'woocommerce_eu_vat_number_dismiss_block_checkout_notice', 'yes', false );
587+
}
588+
589+
/**
590+
* Check if EU VAT inner block is already adjusted in block checkout.
591+
*
592+
* @return boolean
593+
*/
594+
public static function is_eu_vat_block_adjusted() {
595+
$page = get_post( wc_get_page_id( 'checkout' ) );
596+
if ( ! $page ) {
597+
return false;
598+
}
599+
600+
$transient_key = 'wc_eu_vat_block_adjusted';
601+
$cached_result = get_transient( $transient_key );
602+
603+
if ( ! empty( $cached_result ) ) {
604+
return 'yes' === $cached_result;
605+
}
606+
607+
$is_adjusted = false;
608+
$blocks = parse_blocks( $page->post_content );
609+
foreach ( $blocks as $block ) {
610+
if ( 'woocommerce/checkout' === $block['blockName'] ) {
611+
foreach ( $block['innerBlocks'] as $inner_block ) {
612+
if ( 'woocommerce/checkout-fields-block' === $inner_block['blockName'] ) {
613+
$inner_blocks = $inner_block['innerBlocks'];
614+
$block_names = wp_list_pluck( $inner_blocks, 'blockName' );
615+
$last_block = $block_names[ array_key_last( $block_names ) ];
616+
if ( in_array( 'woocommerce/eu-vat-number', $block_names, true ) && 'woocommerce/eu-vat-number' !== $last_block ) {
617+
$is_adjusted = true;
618+
break;
619+
}
620+
}
621+
}
622+
}
623+
}
624+
625+
set_transient( $transient_key, $is_adjusted ? 'yes' : 'no', HOUR_IN_SECONDS );
626+
return $is_adjusted;
627+
}
516628
}
517629

518630
WC_EU_VAT_Admin::init();

languages/woocommerce-eu-vat-number.pot

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# This file is distributed under the GNU General Public License v3.0.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: WooCommerce EU VAT Number 2.9.2\n"
5+
"Project-Id-Version: WooCommerce EU VAT Number 2.9.3\n"
66
"Report-Msgid-Bugs-To: "
77
"https://wordpress.org/support/plugin/woocommerce-eu-vat-number\n"
8-
"POT-Creation-Date: 2024-03-18 14:29:31+00:00\n"
8+
"POT-Creation-Date: 2024-04-22 13:33:45+00:00\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=utf-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
@@ -14,9 +14,9 @@ msgstr ""
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
1515
"X-Generator: node-wp-i18n 1.2.6\n"
1616

17-
#: includes/class-wc-eu-vat-admin.php:59 includes/class-wc-eu-vat-admin.php:172
18-
#: includes/class-wc-eu-vat-admin.php:368
19-
#: includes/class-wc-eu-vat-admin.php:385
17+
#: includes/class-wc-eu-vat-admin.php:63 includes/class-wc-eu-vat-admin.php:182
18+
#: includes/class-wc-eu-vat-admin.php:378
19+
#: includes/class-wc-eu-vat-admin.php:395
2020
#: includes/class-wc-eu-vat-my-account.php:154
2121
#: includes/class-wc-eu-vat-my-account.php:176
2222
#: includes/class-wc-eu-vat-my-account.php:240
@@ -30,59 +30,59 @@ msgstr ""
3030
msgid "VAT number"
3131
msgstr ""
3232

33-
#: includes/class-wc-eu-vat-admin.php:79 includes/class-wc-eu-vat-admin.php:252
33+
#: includes/class-wc-eu-vat-admin.php:83 includes/class-wc-eu-vat-admin.php:262
3434
#: includes/class-wc-eu-vat-privacy.php:20
3535
msgid "EU VAT"
3636
msgstr ""
3737

38-
#: includes/class-wc-eu-vat-admin.php:153
38+
#: includes/class-wc-eu-vat-admin.php:163
3939
msgid "This order is out of scope for EU VAT."
4040
msgstr ""
4141

42-
#: includes/class-wc-eu-vat-admin.php:165
42+
#: includes/class-wc-eu-vat-admin.php:175
4343
msgid "B2B"
4444
msgstr ""
4545

46-
#: includes/class-wc-eu-vat-admin.php:166
46+
#: includes/class-wc-eu-vat-admin.php:176
4747
msgid "Yes"
4848
msgstr ""
4949

50-
#: includes/class-wc-eu-vat-admin.php:166
50+
#: includes/class-wc-eu-vat-admin.php:176
5151
msgid "No"
5252
msgstr ""
5353

54-
#: includes/class-wc-eu-vat-admin.php:177
54+
#: includes/class-wc-eu-vat-admin.php:187
5555
msgid "Validation was not possible"
5656
msgstr ""
5757

58-
#: includes/class-wc-eu-vat-admin.php:186
58+
#: includes/class-wc-eu-vat-admin.php:196
5959
msgid "IP Address"
6060
msgstr ""
6161

62-
#: includes/class-wc-eu-vat-admin.php:187
63-
#: includes/class-wc-eu-vat-admin.php:205
64-
#: includes/class-wc-eu-vat-admin.php:213
62+
#: includes/class-wc-eu-vat-admin.php:197
63+
#: includes/class-wc-eu-vat-admin.php:215
64+
#: includes/class-wc-eu-vat-admin.php:223
6565
msgid "Unknown"
6666
msgstr ""
6767

68-
#: includes/class-wc-eu-vat-admin.php:191
68+
#: includes/class-wc-eu-vat-admin.php:201
6969
msgid "IP Country"
7070
msgstr ""
7171

72-
#: includes/class-wc-eu-vat-admin.php:200
73-
#: includes/class-wc-eu-vat-admin.php:296
72+
#: includes/class-wc-eu-vat-admin.php:210
73+
#: includes/class-wc-eu-vat-admin.php:306
7474
msgid "(self-declared)"
7575
msgstr ""
7676

77-
#: includes/class-wc-eu-vat-admin.php:212
77+
#: includes/class-wc-eu-vat-admin.php:222
7878
msgid "Billing Country"
7979
msgstr ""
8080

81-
#: includes/class-wc-eu-vat-admin.php:284
81+
#: includes/class-wc-eu-vat-admin.php:294
8282
msgid "(validation failed)"
8383
msgstr ""
8484

85-
#: includes/class-wc-eu-vat-admin.php:368
85+
#: includes/class-wc-eu-vat-admin.php:378
8686
#: includes/class-wc-eu-vat-my-account.php:256
8787
#: includes/class-wc-eu-vat-number.php:726
8888
#. translators: %1$s VAT number field label, %2$s VAT number, %3$s Billing
@@ -93,7 +93,7 @@ msgstr ""
9393
msgid "You have entered an invalid %1$s (%2$s) for your billing country (%3$s)."
9494
msgstr ""
9595

96-
#: includes/class-wc-eu-vat-admin.php:464
96+
#: includes/class-wc-eu-vat-admin.php:474
9797
#. translators: %1$s Opening strong tag, %2$s Closing strong tag, %3$s Break
9898
#. tag.
9999
msgid ""
@@ -105,7 +105,7 @@ msgid ""
105105
"from %1$sNorthern Ireland%2$s."
106106
msgstr ""
107107

108-
#: includes/class-wc-eu-vat-admin.php:475
108+
#: includes/class-wc-eu-vat-admin.php:485
109109
#. translators: %1$s Opening strong tag, %2$s Closing strong tag.
110110
msgid ""
111111
"By using %1$sWooCommerce EU VAT Number%2$s plugin, you've agreed that the "
@@ -114,10 +114,20 @@ msgid ""
114114
"tax specific questions."
115115
msgstr ""
116116

117-
#: includes/class-wc-eu-vat-admin.php:480
117+
#: includes/class-wc-eu-vat-admin.php:490
118118
msgid "I understand"
119119
msgstr ""
120120

121+
#: includes/class-wc-eu-vat-admin.php:561
122+
#. translators: %1$s - <strong>, %2$s - </strong>, %3$s - Link to edit checkout
123+
#. page, %4$s - closing tag
124+
msgid ""
125+
"%1$sWooCommerce EU VAT Number%2$s plugin adds a VAT number field to the "
126+
"checkout block though it may appear after the \"Place Order\" button. "
127+
"Please %3$sedit%4$s the checkout block to adjust the position of the VAT "
128+
"Number field accordingly."
129+
msgstr ""
130+
121131
#: includes/class-wc-eu-vat-extend-store-endpoint.php:191
122132
msgid "Location confirmation."
123133
msgstr ""

woocommerce-eu-vat-number.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
* Requires Plugins: woocommerce
55
* Plugin URI: https://woocommerce.com/products/eu-vat-number/
66
* Description: The EU VAT Number extension lets you collect and validate EU VAT numbers during checkout to identify B2B transactions verses B2C. IP Addresses can also be validated to ensure they match the billing address. EU businesses with a valid VAT number can have their VAT removed prior to payment.
7-
* Version: 2.9.2
7+
* Version: 2.9.3
88
* Author: WooCommerce
99
* Author URI: https://woocommerce.com/
1010
* Text Domain: woocommerce-eu-vat-number
1111
* Domain Path: /languages
1212
* Requires at least: 6.3
1313
* Tested up to: 6.5
14-
* WC requires at least: 8.5
15-
* WC tested up to: 8.7
14+
* WC requires at least: 8.6
15+
* WC tested up to: 8.8
1616
* Requires PHP: 7.4
1717
* PHP tested up to: 8.3
1818
*
@@ -26,7 +26,7 @@
2626

2727
// phpcs:disable WordPress.Files.FileName
2828

29-
define( 'WC_EU_VAT_VERSION', '2.9.2' ); // WRCS: DEFINED_VERSION.
29+
define( 'WC_EU_VAT_VERSION', '2.9.3' ); // WRCS: DEFINED_VERSION.
3030
define( 'WC_EU_VAT_FILE', __FILE__ );
3131
define( 'WC_EU_ABSPATH', __DIR__ . '/' );
3232
define( 'WC_EU_VAT_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );

0 commit comments

Comments
 (0)