Skip to content

Commit

Permalink
Updates to 2.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
WooCommerce committed Apr 23, 2024
1 parent 615b15d commit 7a3b26d
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 43 deletions.
39 changes: 30 additions & 9 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
( function( $ ) {
$(document.body).on( 'order-totals-recalculate-before', function( e, data ) {
if( data && $( '#_billing_vat_number' ).length ) {
data._billing_vat_number = $( '#_billing_vat_number' ).val();
data._billing_country = $( '#_billing_country' ).val();
data._shipping_country = $( '#_shipping_country' ).val();
data._billing_postcode = $( '#_billing_postcode' ).val();
/* global wc_eu_vat_admin_params */
( function ( $ ) {
$( document.body ).on(
'order-totals-recalculate-before',
function ( e, data ) {
if ( data && $( '#_billing_vat_number' ).length ) {
data._billing_vat_number = $( '#_billing_vat_number' ).val();
data._billing_country = $( '#_billing_country' ).val();
data._shipping_country = $( '#_shipping_country' ).val();
data._billing_postcode = $( '#_billing_postcode' ).val();
}
}
});
}( jQuery ) );
);
} )( jQuery );

( function ( $ ) {
$( '.wc-eu-vat-block-checkout-notice' ).on(
'click',
'.notice-dismiss',
function () {
$.ajax( {
url: wc_eu_vat_admin_params.ajax_url,
type: 'POST',
data: {
action: 'wc_eu_vat_dismiss_checkout_notice',
security: wc_eu_vat_admin_params.dismiss_nonce,
},
} );
}
);
} )( jQuery );
2 changes: 1 addition & 1 deletion assets/js/admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** EU VAT Number Changelog ***

2024-04-22 - version 2.9.3
* Add - Show an admin notice letting users know to adjust the position of the VAT number field in the Checkout Block.
* Dev - Bump WooCommerce "tested up to" version 8.8.
* Dev - Bump WooCommerce minimum supported version to 8.6.

2024-03-18 - version 2.9.2
* Add - Option to disable Express Pay buttons for B2B stores (WooPayments compatibility).
* Add - Document WooPayments compatibility.
Expand Down
122 changes: 117 additions & 5 deletions includes/class-wc-eu-vat-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static function init() {
add_action( 'admin_notices', array( __CLASS__, 'maybe_show_admin_notice' ) );
add_action( 'update_option_woocommerce_default_country', array( __CLASS__, 'reset_admin_notice_display' ), 10, 3 );
add_action( 'update_option_woocommerce_store_postcode', array( __CLASS__, 'reset_admin_notice_display' ), 10, 3 );

// Notice for adjust vat number field on Block checkout.
add_action( 'wp_ajax_wc_eu_vat_dismiss_checkout_notice', array( __CLASS__, 'dismiss_block_checkout_notice' ), 10 );
add_action( 'admin_notices', array( __CLASS__, 'maybe_show_admin_notice_for_block_checkout' ) );
}

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

// Load script only on add/edit order page.
if ( $is_order_edit_screen ) {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'wc-eu-vat-admin', WC_EU_VAT_PLUGIN_URL . '/assets/js/admin' . $suffix . '.js', array( 'jquery' ), WC_EU_VAT_VERSION, true );
}
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'wc-eu-vat-admin', WC_EU_VAT_PLUGIN_URL . '/assets/js/admin' . $suffix . '.js', array( 'jquery' ), WC_EU_VAT_VERSION, true );

wp_localize_script(
'wc-eu-vat-admin',
'wc_eu_vat_admin_params',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'dismiss_nonce' => wp_create_nonce( 'dismiss_block_checkout_notice' ),
)
);
}

/**
Expand Down Expand Up @@ -513,6 +523,108 @@ public static function dismiss_eu_vat_disclaimer() {
public static function reset_admin_notice_display( $old_value, $value, $option ) {
delete_option( 'woocommerce_eu_vat_number_dismiss_disclaimer' );
}

/**
* Display admin notice for block checkout.
*
* @since 2.9.3
*/
public static function maybe_show_admin_notice_for_block_checkout() {
// Check whether disclaimer is already dismissed or taxes are not enabled.
if (
! wc_tax_enabled() ||
'yes' === get_option( 'woocommerce_eu_vat_number_dismiss_block_checkout_notice', 'no' ) ||
! current_user_can( 'manage_woocommerce' ) // phpcs:ignore WordPress.WP.Capabilities.Unknown
) {
return;
}

// Check if the block checkout is the default checkout.
if ( ! WC_Blocks_Utils::has_block_in_page( wc_get_page_id( 'checkout' ), 'woocommerce/checkout' ) ) {
return;
}

// Check if it is already adjusted.
if ( self::is_eu_vat_block_adjusted() ) {
update_option( 'woocommerce_eu_vat_number_dismiss_block_checkout_notice', 'yes', false );
return;
}
?>

<div class="notice notice-info wc-eu-vat-block-checkout-notice is-dismissible">
<p>
<?php
// translators: %1$s Opening strong tag, %2$s Closing strong tag.
echo wp_kses_post(
sprintf(
/* translators: %1$s - <strong>, %2$s - </strong>, %3$s - Link to edit checkout page, %4$s - closing tag */
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' ),
'<strong>',
'</strong>',
'<a href="' . esc_url( get_edit_post_link( wc_get_page_id( 'checkout' ) ) ) . '">',
'</a>'
)
);
?>
</p>
</div>
<?php
}

/**
* Dismiss Block checkout notice.
*
* @since 2.9.3
*/
public static function dismiss_block_checkout_notice() {
check_ajax_referer( 'dismiss_block_checkout_notice', 'security' );

if ( ! current_user_can( 'manage_woocommerce' ) ) { // phpcs:ignore WordPress.WP.Capabilities.Unknown
return;
}

update_option( 'woocommerce_eu_vat_number_dismiss_block_checkout_notice', 'yes', false );
}

/**
* Check if EU VAT inner block is already adjusted in block checkout.
*
* @return boolean
*/
public static function is_eu_vat_block_adjusted() {
$page = get_post( wc_get_page_id( 'checkout' ) );
if ( ! $page ) {
return false;
}

$transient_key = 'wc_eu_vat_block_adjusted';
$cached_result = get_transient( $transient_key );

if ( ! empty( $cached_result ) ) {
return 'yes' === $cached_result;
}

$is_adjusted = false;
$blocks = parse_blocks( $page->post_content );
foreach ( $blocks as $block ) {
if ( 'woocommerce/checkout' === $block['blockName'] ) {
foreach ( $block['innerBlocks'] as $inner_block ) {
if ( 'woocommerce/checkout-fields-block' === $inner_block['blockName'] ) {
$inner_blocks = $inner_block['innerBlocks'];
$block_names = wp_list_pluck( $inner_blocks, 'blockName' );
$last_block = $block_names[ array_key_last( $block_names ) ];
if ( in_array( 'woocommerce/eu-vat-number', $block_names, true ) && 'woocommerce/eu-vat-number' !== $last_block ) {
$is_adjusted = true;
break;
}
}
}
}
}

set_transient( $transient_key, $is_adjusted ? 'yes' : 'no', HOUR_IN_SECONDS );
return $is_adjusted;
}
}

WC_EU_VAT_Admin::init();
58 changes: 34 additions & 24 deletions languages/woocommerce-eu-vat-number.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# This file is distributed under the GNU General Public License v3.0.
msgid ""
msgstr ""
"Project-Id-Version: WooCommerce EU VAT Number 2.9.2\n"
"Project-Id-Version: WooCommerce EU VAT Number 2.9.3\n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/woocommerce-eu-vat-number\n"
"POT-Creation-Date: 2024-03-18 14:29:31+00:00\n"
"POT-Creation-Date: 2024-04-22 13:33:45+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand All @@ -14,9 +14,9 @@ msgstr ""
"Language-Team: LANGUAGE <[email protected]>\n"
"X-Generator: node-wp-i18n 1.2.6\n"

#: includes/class-wc-eu-vat-admin.php:59 includes/class-wc-eu-vat-admin.php:172
#: includes/class-wc-eu-vat-admin.php:368
#: includes/class-wc-eu-vat-admin.php:385
#: includes/class-wc-eu-vat-admin.php:63 includes/class-wc-eu-vat-admin.php:182
#: includes/class-wc-eu-vat-admin.php:378
#: includes/class-wc-eu-vat-admin.php:395
#: includes/class-wc-eu-vat-my-account.php:154
#: includes/class-wc-eu-vat-my-account.php:176
#: includes/class-wc-eu-vat-my-account.php:240
Expand All @@ -30,59 +30,59 @@ msgstr ""
msgid "VAT number"
msgstr ""

#: includes/class-wc-eu-vat-admin.php:79 includes/class-wc-eu-vat-admin.php:252
#: includes/class-wc-eu-vat-admin.php:83 includes/class-wc-eu-vat-admin.php:262
#: includes/class-wc-eu-vat-privacy.php:20
msgid "EU VAT"
msgstr ""

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

#: includes/class-wc-eu-vat-admin.php:165
#: includes/class-wc-eu-vat-admin.php:175
msgid "B2B"
msgstr ""

#: includes/class-wc-eu-vat-admin.php:166
#: includes/class-wc-eu-vat-admin.php:176
msgid "Yes"
msgstr ""

#: includes/class-wc-eu-vat-admin.php:166
#: includes/class-wc-eu-vat-admin.php:176
msgid "No"
msgstr ""

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

#: includes/class-wc-eu-vat-admin.php:186
#: includes/class-wc-eu-vat-admin.php:196
msgid "IP Address"
msgstr ""

#: includes/class-wc-eu-vat-admin.php:187
#: includes/class-wc-eu-vat-admin.php:205
#: includes/class-wc-eu-vat-admin.php:213
#: includes/class-wc-eu-vat-admin.php:197
#: includes/class-wc-eu-vat-admin.php:215
#: includes/class-wc-eu-vat-admin.php:223
msgid "Unknown"
msgstr ""

#: includes/class-wc-eu-vat-admin.php:191
#: includes/class-wc-eu-vat-admin.php:201
msgid "IP Country"
msgstr ""

#: includes/class-wc-eu-vat-admin.php:200
#: includes/class-wc-eu-vat-admin.php:296
#: includes/class-wc-eu-vat-admin.php:210
#: includes/class-wc-eu-vat-admin.php:306
msgid "(self-declared)"
msgstr ""

#: includes/class-wc-eu-vat-admin.php:212
#: includes/class-wc-eu-vat-admin.php:222
msgid "Billing Country"
msgstr ""

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

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

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

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

#: includes/class-wc-eu-vat-admin.php:480
#: includes/class-wc-eu-vat-admin.php:490
msgid "I understand"
msgstr ""

#: includes/class-wc-eu-vat-admin.php:561
#. translators: %1$s - <strong>, %2$s - </strong>, %3$s - Link to edit checkout
#. page, %4$s - closing tag
msgid ""
"%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."
msgstr ""

#: includes/class-wc-eu-vat-extend-store-endpoint.php:191
msgid "Location confirmation."
msgstr ""
Expand Down
8 changes: 4 additions & 4 deletions woocommerce-eu-vat-number.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* Requires Plugins: woocommerce
* Plugin URI: https://woocommerce.com/products/eu-vat-number/
* 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.
* Version: 2.9.2
* Version: 2.9.3
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Text Domain: woocommerce-eu-vat-number
* Domain Path: /languages
* Requires at least: 6.3
* Tested up to: 6.5
* WC requires at least: 8.5
* WC tested up to: 8.7
* WC requires at least: 8.6
* WC tested up to: 8.8
* Requires PHP: 7.4
* PHP tested up to: 8.3
*
Expand All @@ -26,7 +26,7 @@

// phpcs:disable WordPress.Files.FileName

define( 'WC_EU_VAT_VERSION', '2.9.2' ); // WRCS: DEFINED_VERSION.
define( 'WC_EU_VAT_VERSION', '2.9.3' ); // WRCS: DEFINED_VERSION.
define( 'WC_EU_VAT_FILE', __FILE__ );
define( 'WC_EU_ABSPATH', __DIR__ . '/' );
define( 'WC_EU_VAT_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
Expand Down

0 comments on commit 7a3b26d

Please sign in to comment.