diff --git a/assets/css/admin.css b/assets/css/admin.css index d8e7e02..b2bc42d 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -1 +1 @@ -#shipping_class_priorities table input,#shipping_class_priorities table select,table#shipping_rates input,table#shipping_rates select{width:100%}#shipping_class_priorities table input[type=checkbox],table#shipping_rates input[type=checkbox]{width:auto}#shipping_class_priorities table td,table#shipping_rates td{cursor:move}#shipping_class_priorities table a.dupe,#shipping_class_priorities table a.remove,table#shipping_rates a.dupe,table#shipping_rates a.remove{float:right;margin-left:4px}#shipping_class_priorities table td,#shipping_class_priorities table th,table#shipping_rates td,table#shipping_rates th{padding:15px 10px;vertical-align:middle}#shipping_class_priorities table tr:nth-child(even) td,#shipping_class_priorities table tr:nth-child(even) th,table#shipping_rates tr:nth-child(even) td,table#shipping_rates tr:nth-child(even) th{background:#fafafa}#shipping_class_priorities table td.checkbox,#shipping_class_priorities table th.checkbox,table#shipping_rates td.checkbox,table#shipping_rates th.checkbox{text-align:center}#shipping_class_priorities table td .disabled,table#shipping_rates td .disabled{opacity:.5}#shipping_class_priorities table .check-column,table#shipping_rates .check-column{width:24px;min-width:24px!important;text-align:center;padding:15px 10px}#shipping_class_priorities table .check-column input,table#shipping_rates .check-column input{width:auto;vertical-align:middle;margin:0 0 0 8px}table#shipping_rates td.minmax input.error{background:#e9e6ed}table#shipping_rates td.minmax .tips{width:20px;height:20px;background:#ffba00;color:#fff;border-radius:100%;line-height:1.3;font-weight:700;text-align:center;display:inline-block;margin-top:4px} \ No newline at end of file +table#shipping_rates input,table#shipping_rates select,#shipping_class_priorities table input,#shipping_class_priorities table select{width:100%}table#shipping_rates input[type=checkbox],#shipping_class_priorities table input[type=checkbox]{width:auto}table#shipping_rates td,#shipping_class_priorities table td{cursor:move}table#shipping_rates a.remove,table#shipping_rates a.dupe,#shipping_class_priorities table a.remove,#shipping_class_priorities table a.dupe{float:right;margin-left:4px}table#shipping_rates td,table#shipping_rates th,#shipping_class_priorities table td,#shipping_class_priorities table th{padding:15px 10px;vertical-align:middle}table#shipping_rates tr:nth-child(even) td,table#shipping_rates tr:nth-child(even) th,#shipping_class_priorities table tr:nth-child(even) td,#shipping_class_priorities table tr:nth-child(even) th{background:#fafafa}table#shipping_rates th.checkbox,table#shipping_rates td.checkbox,#shipping_class_priorities table th.checkbox,#shipping_class_priorities table td.checkbox{text-align:center}table#shipping_rates td .disabled,#shipping_class_priorities table td .disabled{opacity:.5}table#shipping_rates .check-column,#shipping_class_priorities table .check-column{width:24px;min-width:24px !important;text-align:center;padding:15px 10px}table#shipping_rates .check-column input,#shipping_class_priorities table .check-column input{width:auto;vertical-align:middle;margin:0 0 0 8px}table#shipping_rates td.minmax input.error{background:#e9e6ed}table#shipping_rates td.minmax .tips{width:20px;height:20px;background:#ffba00;color:white;border-radius:100%;line-height:1.3;font-weight:bold;text-align:center;display:inline-block;margin-top:4px} diff --git a/assets/js/frontend-checkout.min.js b/assets/js/frontend-checkout.min.js deleted file mode 100644 index d01bf0c..0000000 --- a/assets/js/frontend-checkout.min.js +++ /dev/null @@ -1 +0,0 @@ -function wc_trs_display_abort_text(e){var o=jQuery(".woocommerce-info"),c=jQuery("form.woocommerce-checkout .woocommerce-info"),r=!1;c.each(function(e,o){var c=jQuery(o);"yes"===c.data("wc_trs")&&(!0===r&&c.remove(),r=!0)}),!1!==r&&o.each(function(e,o){var c=jQuery(o);"yes"===c.data("wc_trs")&&c.parents("form.woocommerce-checkout").length<1&&c.remove()})}jQuery(document.body).on("updated_checkout checkout_error",function(e){wc_trs_display_abort_text()}); diff --git a/assets/js/table-rate-rows.min.js b/assets/js/table-rate-rows.min.js deleted file mode 100644 index b7a5a37..0000000 --- a/assets/js/table-rate-rows.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(a,i,e,o){var n=e.template("table-rate-shipping-row-template"),t=a("#mainform"),r=a("#shipping_rates"),s=r.find("tbody.table_rates"),p={init:function(){t.on("change","#woocommerce_table_rate_calculation_type",this.onCalculationTypeChange),r.on("change",'select[name^="shipping_condition"]',this.onShippingConditionChange).on("change",'input[name^="shipping_abort["]',this.onShippingAbortChange).on("click","a.add-rate",this.onAddRate).on("click","a.remove",this.onRemoveRate).on("click","a.dupe",this.onDupeRate);var i=s.data("rates");a(i).each(function(e){var t=s.find(".table_rate").length;s.append(n({rate:i[e],index:t}))}),a('label[for="woocommerce_table_rate_handling_fee"], label[for="woocommerce_table_rate_max_cost"], label[for="woocommerce_table_rate_min_cost"]',t).each(function(e,t){a(t).data("o_label",a(t).text())}),a('#woocommerce_table_rate_calculation_type, select[name^="shipping_condition"], input[name^="shipping_abort["]',t).change(),s.sortable({items:"tr",cursor:"move",axis:"y",handle:"td",scrollSensitivity:40,helper:function(e,t){return t.children().each(function(){a(this).width(a(this).width())}),t.css("left","0"),t},start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style"),p.reindexRows()}})},onCalculationTypeChange:function(){var e=a(this).val();"item"==e?a("td.cost_per_item input").attr("disabled","disabled").addClass("disabled"):a("td.cost_per_item input").removeAttr("disabled").removeClass("disabled"),e?(a("#shipping_class_priorities").hide(),a("td.shipping_label, th.shipping_label").hide()):(a("#shipping_class_priorities").show(),a("td.shipping_label, th.shipping_label").show()),e||(a("#shipping_class_priorities span.description.per_order").show(),a("#shipping_class_priorities span.description.per_class").hide());var n=i.i18n.order;"item"==e?n=i.i18n.item:"line"==e?n=i.i18n.line_item:"class"==e&&(n=i.i18n.class),a('label[for="woocommerce_table_rate_handling_fee"], label[for="woocommerce_table_rate_max_cost"], label[for="woocommerce_table_rate_min_cost"]').each(function(e,t){var i=a(t).data("o_label");i=i.replace("[item]",n),a(t).text(i)})},onShippingConditionChange:function(){var e=a(this).val(),t=a(this).closest("tr");""==e?t.find('input[name^="shipping_min"], input[name^="shipping_max"]').val("").prop("disabled",!0).addClass("disabled"):t.find('input[name^="shipping_min"], input[name^="shipping_max"]').prop("disabled",!1).removeClass("disabled")},onShippingAbortChange:function(){var e=a(this).is(":checked"),t=a(this).closest("tr");e?(t.find("td.cost").hide(),t.find("td.abort_reason").show(),t.find('input[name^="shipping_per_item"], input[name^="shipping_cost_per_weight"], input[name^="shipping_cost_percent"], input[name^="shipping_cost"], input[name^="shipping_label"]').prop("disabled",!0).addClass("disabled")):(t.find("td.cost").show(),t.find("td.abort_reason").hide(),t.find('input[name^="shipping_per_item"], input[name^="shipping_cost_per_weight"], input[name^="shipping_cost_percent"], input[name^="shipping_cost"], input[name^="shipping_label"]').prop("disabled",!1).removeClass("disabled")),a("#woocommerce_table_rate_calculation_type").change()},onAddRate:function(e){e.preventDefault();var t=s,i=t.find(".table_rate").length;t.append(n({rate:{rate_id:"",rate_class:"",rate_condition:"",rate_min:"",rate_max:"",rate_priority:"",rate_abort:"",rate_abort_reason:"",rate_cost:"",rate_cost_per_item:"",rate_cost_per_weight_unit:"",rate_cost_percent:"",rate_label:""},index:i})),a('#woocommerce_table_rate_calculation_type, select[name^="shipping_condition"], input[name^="shipping_abort["]',r).change()},onRemoveRate:function(e){if(e.preventDefault(),confirm(i.i18n.delete_rates)){var n=[];s.find("tr td.check-column input:checked").each(function(e,t){var i=a(t).closest("tr.table_rate").find(".rate_id").val();n.push(i),a(t).closest("tr.table_rate").addClass("deleting")});var t={action:"woocommerce_table_rate_delete",rate_id:n,security:i.delete_rates_nonce};a.post(o,t,function(e){a("tr.deleting").fadeOut("300",function(){a(this).remove()})})}},onDupeRate:function(e){e.preventDefault(),confirm(i.i18n.dupe_rates)&&(s.find("tr td.check-column input:checked").each(function(e,t){var i=a(t).closest("tr").clone();i.find(".rate_id").val("0"),s.append(i)}),p.reindexRows())},reindexRows:function(){var n=0;s.find("tr").each(function(e,t){a("input.text, input.checkbox, select.select, input[type=hidden]",t).each(function(e,t){var i=a(t);i.attr("name",i.attr("name").replace(/\[([^[]*)\]/,"["+n+"]"))}),n++})}};p.init()}(jQuery,woocommerce_shipping_table_rate_rows,wp,ajaxurl); diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..ea3e8b8 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,5 @@ +module.exports = { + ignore: [], + presets: [ '@wordpress/babel-preset-default' ], + plugins: [], +}; diff --git a/changelog.txt b/changelog.txt index 430224a..1c985aa 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,8 @@ *** Table Rate Shipping Changelog *** +2024-05-27 - version 3.2.0 +* Add - Abort messages compatibility with cart and checkout blocks. + 2024-04-15 - version 3.1.9 * Fix - Notice is displayed when rate minimum and rate maximum is equal. diff --git a/client/abort-notices/index.js b/client/abort-notices/index.js new file mode 100644 index 0000000..58f427f --- /dev/null +++ b/client/abort-notices/index.js @@ -0,0 +1,108 @@ +/** + * Block Notices + * + * This file is responsible for rendering Abort Messages from the Table Rate Shipping plugin. + * + * @package WooCommerce_Table_Rate_Shipping + */ + +const { useSelect } = window.wp.data; +const { registerPlugin } = window.wp.plugins; +const { ExperimentalOrderShippingPackages, StoreNotice } = window.wc.blocksCheckout; +const { RawHTML } = window.wp.element; + +/** + * Create a store notice component. + * + * @param notice + * @param index + * @param type + * @returns {JSX.Element} + */ +const createStoreNotice = ( notice, index, type = 'info' ) => { + if ( 'debug' === type ) { + type = 'info'; + } + + const message = {notice}; + + return ( + + {message} + + ); +}; + +/** + * Utility function to get the abort message for the current package hashes. + * + * @param messages + * @param packageHashes + * @returns {string|null} + */ +const getAbortMessageForCurrentPackage = ( messages, packageHashes ) => { + if ( !messages || !packageHashes ) { + return null; + } + + for ( const hash of packageHashes ) { + if ( messages[hash] ) { + return messages[hash]; + } + } + return null; +}; + +/** + * Notices component. + * + * @param messages + * @param packageHashes + * @returns {JSX.Element} + * @constructor + */ +const Notices = ({ messages, packageHashes }) => { + const currentMessage = getAbortMessageForCurrentPackage(messages, packageHashes); + + if ( !currentMessage ) { + return null; + } + + return ( +
+ {createStoreNotice( currentMessage, 0, 'info' )} +
+ ); +}; + +const render = () => { + const { abortMessages, hasShippingRates, packageHashes } = useSelect((select) => { + const storeCartData = select( 'wc/store/cart' ).getCartData(); + const shippingRates = storeCartData?.shippingRates || []; + const hasShippingRates = shippingRates.some( rate => rate.shipping_rates.length > 0 ); + const abortMessages = storeCartData?.extensions?.['woocommerce_table_rate_shipping']?.abort_messages; + const packageHashes = storeCartData?.extensions?.['woocommerce_table_rate_shipping']?.package_hashes; + + return { + abortMessages, + hasShippingRates, + packageHashes, + }; + }, []); + + // Ensure we only show abort messages if no shipping rates are available. + if (hasShippingRates) { + return null; + } + + return ( + + + + ); +}; + +registerPlugin('woocommerce-trs-abort-notices', { + render, + scope: 'woocommerce-checkout', +}); \ No newline at end of file diff --git a/dist/woocommerce-trs-abort-notices.asset.php b/dist/woocommerce-trs-abort-notices.asset.php new file mode 100644 index 0000000..9203cc0 --- /dev/null +++ b/dist/woocommerce-trs-abort-notices.asset.php @@ -0,0 +1 @@ + array('react'), 'version' => 'bba503e536fb0fe8a723'); diff --git a/dist/woocommerce-trs-abort-notices.js b/dist/woocommerce-trs-abort-notices.js new file mode 100644 index 0000000..f7725b6 --- /dev/null +++ b/dist/woocommerce-trs-abort-notices.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={609:e=>{e.exports=window.React}},t={};function s(r){var a=t[r];if(void 0!==a)return a.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,s),o.exports}s.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},s.d=(e,t)=>{for(var r in t)s.o(t,r)&&!s.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e=s(609);const{useSelect:t}=window.wp.data,{registerPlugin:r}=window.wp.plugins,{ExperimentalOrderShippingPackages:a,StoreNotice:o}=window.wc.blocksCheckout,{RawHTML:n}=window.wp.element,c=({messages:t,packageHashes:s})=>{const r=((e,t)=>{if(!e||!t)return null;for(const s of t)if(e[s])return e[s];return null})(t,s);return r?(0,e.createElement)("div",{className:"woocommerce-table-rate-shipping-block-notices"},((t,s,r="info")=>{"debug"===r&&(r="info");const a=(0,e.createElement)(n,null,t);return(0,e.createElement)(o,{key:s,status:r,isDismissible:!1},a)})(r,0,"info")):null};r("woocommerce-trs-abort-notices",{render:()=>{const{abortMessages:s,hasShippingRates:r,packageHashes:o}=t((e=>{const t=e("wc/store/cart").getCartData(),s=(t?.shippingRates||[]).some((e=>e.shipping_rates.length>0)),r=t?.extensions?.woocommerce_table_rate_shipping?.abort_messages,a=t?.extensions?.woocommerce_table_rate_shipping?.package_hashes;return{abortMessages:r,hasShippingRates:s,packageHashes:a}}),[]);return r?null:(0,e.createElement)(a,null,(0,e.createElement)(c,{messages:s,packageHashes:o}))},scope:"woocommerce-checkout"})})()})(); \ No newline at end of file diff --git a/includes/class-blocks-integration.php b/includes/class-blocks-integration.php new file mode 100644 index 0000000..cc49d2f --- /dev/null +++ b/includes/class-blocks-integration.php @@ -0,0 +1,113 @@ +register_scripts(); + } + + /** + * Returns an array of script handles to enqueue in the frontend context. + * + * @return string[] + */ + public function get_script_handles(): array { + return array( 'woocommerce-trs-abort-notices' ); + } + + /** + * Returns an array of script handles to enqueue in the editor context. + * + * @return string[] + */ + public function get_editor_script_handles(): array { + return array(); + } + + /** + * An array of key, value pairs of data made available to the block on the client side. + * + * @return array + */ + public function get_script_data(): array { + return array(); + } + + /** + * Registers the scripts and styles for the integration. + */ + public function register_scripts() { + + foreach ( $this->get_script_handles() as $handle ) { + $this->register_script( $handle ); + } + } + + /** + * Register a script for the integration. + * + * @param string $handle Script handle. + */ + protected function register_script( string $handle ) { + $script_path = $handle . '.js'; + $script_url = WC_TABLE_RATE_SHIPPING_DIST_URL . $script_path; + + $script_asset_path = WC_TABLE_RATE_SHIPPING_DIST_DIR . $handle . '.asset.php'; + $script_asset = file_exists( $script_asset_path ) + ? require $script_asset_path // nosemgrep: audit.php.lang.security.file.inclusion-arg --- This is a safe file inclusion. + : array( + 'dependencies' => array(), + 'version' => $this->get_file_version( WC_TABLE_RATE_SHIPPING_DIST_DIR . $script_path ), + ); + + wp_register_script( + $handle, + $script_url, + $script_asset['dependencies'], + $script_asset['version'], + true + ); + + wp_set_script_translations( + $handle, + 'woocommerce-table-rate-shipping', + WC_TABLE_RATE_SHIPPING_MAIN_ABSPATH . '/languages' + ); + } + + /** + * Get the file modified time as a cache buster if we're in dev mode. + * + * @param string $file Local path to the file. + * + * @return string The cache buster value to use for the given file. + */ + protected function get_file_version( string $file ): string { + if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && file_exists( $file ) ) { + return filemtime( $file ); + } + + return TABLE_RATE_SHIPPING_VERSION; + } +} diff --git a/includes/class-store-api-extension.php b/includes/class-store-api-extension.php new file mode 100644 index 0000000..2ea2978 --- /dev/null +++ b/includes/class-store-api-extension.php @@ -0,0 +1,100 @@ +get( ExtendSchema::class ); + self::extend_store(); + } + + /** + * Registers the data into each endpoint. + */ + public static function extend_store() { + + self::$extend->register_endpoint_data( + array( + 'endpoint' => CartSchema::IDENTIFIER, + 'namespace' => self::IDENTIFIER, + 'data_callback' => array( static::class, 'data' ), + 'schema_callback' => array( static::class, 'schema' ), + 'schema_type' => ARRAY_A, + ) + ); + } + + /** + * Store API extension data callback. + * + * @return array + */ + public static function data() { + $abort = WC()->session->get( WC_Table_Rate_Shipping::$abort_key ); + $abort = is_array( $abort ) ? $abort : array(); + + $packages = WC()->cart->get_shipping_packages(); + $package_hashes = array(); + foreach ( $packages as $package ) { + $package_hashes[] = WC_Table_Rate_Shipping::create_package_hash( $package ); + } + + return array( + 'abort_messages' => $abort, + 'package_hashes' => $package_hashes, + ); + } + + /** + * Store API extension schema callback. + * + * @return array Registered schema. + */ + public static function schema() { + return array( + 'abort_messages' => array( + 'description' => __( 'Abort messages from Table Rate Shipping.', 'woocommerce-table-rate-shipping' ), + 'type' => 'array', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, + ), + 'package_hashes' => array( + 'description' => __( 'Current package hashes.', 'woocommerce-table-rate-shipping' ), + 'type' => 'array', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, + ), + ); + } +} diff --git a/includes/class-wc-shipping-table-rate.php b/includes/class-wc-shipping-table-rate.php index 2e9b211..fdc486c 100644 --- a/includes/class-wc-shipping-table-rate.php +++ b/includes/class-wc-shipping-table-rate.php @@ -1376,21 +1376,24 @@ public function maybe_add_error_notices_on_settings_saved() { return; } - add_action( 'woocommerce_settings_shipping', function () { + add_action( + 'woocommerce_settings_shipping', + function () { - $message = sprintf( + $message = sprintf( /* translators: %s: message */ - '

%s

', - esc_html__( - 'You have overlapping shipping rates defined, which may offer multiple options for the same criteria at checkout. If this is not your intention please review and adjust your rates and verify it on the cart/checkout pages.', - 'woocommerce-table-rate-shipping' - ) - ); + '

%s

', + esc_html__( + 'You have overlapping shipping rates defined, which may offer multiple options for the same criteria at checkout. If this is not your intention please review and adjust your rates and verify it on the cart/checkout pages.', + 'woocommerce-table-rate-shipping' + ) + ); - echo wp_kses_post( $message ); - }, 0 ); + echo wp_kses_post( $message ); + }, + 0 + ); // phpcs:enable WordPress.Security.NonceVerification.Recommended } - } diff --git a/includes/class-wc-table-rate-shipping.php b/includes/class-wc-table-rate-shipping.php index 8d0c5b7..e2114dc 100644 --- a/includes/class-wc-table-rate-shipping.php +++ b/includes/class-wc-table-rate-shipping.php @@ -29,9 +29,38 @@ public function __construct() { add_filter( 'site_transient_update_plugins', array( $this, 'filter_out_trs' ) ); add_action( 'plugins_loaded', array( $this, 'init' ) ); add_action( 'before_woocommerce_init', array( $this, 'declare_hpos_compatibility' ) ); + add_action( 'woocommerce_blocks_loaded', array( $this, 'register_blocks_integration' ) ); + add_action( 'woocommerce_blocks_loaded', array( $this, 'extend_store_api' ) ); register_activation_hook( WC_TABLE_RATE_SHIPPING_MAIN_FILE, array( $this, 'install' ) ); } + /** + * Register blocks integration. + */ + public function register_blocks_integration() { + require_once WC_TABLE_RATE_SHIPPING_MAIN_ABSPATH . 'includes/class-blocks-integration.php'; + add_action( + 'woocommerce_blocks_cart_block_registration', + function ( $integration_registry ) { + $integration_registry->register( new Blocks_Integration() ); + } + ); + add_action( + 'woocommerce_blocks_checkout_block_registration', + function ( $integration_registry ) { + $integration_registry->register( new Blocks_Integration() ); + } + ); + } + + /** + * Extend the store API. + */ + public function extend_store_api() { + require_once WC_TABLE_RATE_SHIPPING_MAIN_ABSPATH . 'includes/class-store-api-extension.php'; + Store_API_Extension::init(); + } + /** * We need to filter out woocommerce-table-rate-shipping from .org since that's a different * plugin and users should not be redirected there. diff --git a/languages/woocommerce-table-rate-shipping.pot b/languages/woocommerce-table-rate-shipping.pot index af9aa5f..06335ca 100644 --- a/languages/woocommerce-table-rate-shipping.pot +++ b/languages/woocommerce-table-rate-shipping.pot @@ -2,10 +2,10 @@ # This file is distributed under the GNU General Public License v3.0. msgid "" msgstr "" -"Project-Id-Version: WooCommerce Table Rate Shipping 3.1.9\n" +"Project-Id-Version: WooCommerce Table Rate Shipping 3.2.0\n" "Report-Msgid-Bugs-To: " "https://wordpress.org/support/plugin/woocommerce-table-rate-shipping\n" -"POT-Creation-Date: 2024-04-15 19:47:30+00:00\n" +"POT-Creation-Date: 2024-05-27 19:14:29+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -33,6 +33,14 @@ msgstr "" msgid "Min value is overlapping with max value from row %d." msgstr "" +#: includes/class-store-api-extension.php:87 +msgid "Abort messages from Table Rate Shipping." +msgstr "" + +#: includes/class-store-api-extension.php:93 +msgid "Current package hashes." +msgstr "" + #: includes/class-wc-shipping-table-rate-privacy.php:20 #: includes/class-wc-shipping-table-rate.php:122 msgid "Table rates" @@ -220,7 +228,7 @@ msgstr "" msgid "Class Priorities" msgstr "" -#: includes/class-wc-shipping-table-rate.php:1384 +#: includes/class-wc-shipping-table-rate.php:1386 #. translators: %s: message msgid "" "You have overlapping shipping rates defined, which may offer multiple " @@ -229,48 +237,48 @@ msgid "" "pages." msgstr "" -#: includes/class-wc-table-rate-shipping.php:138 +#: includes/class-wc-table-rate-shipping.php:167 msgid "View Documentation" msgstr "" -#: includes/class-wc-table-rate-shipping.php:138 +#: includes/class-wc-table-rate-shipping.php:167 msgid "Docs" msgstr "" -#: includes/class-wc-table-rate-shipping.php:147 +#: includes/class-wc-table-rate-shipping.php:176 msgid "Visit Premium Customer Support Forum" msgstr "" -#: includes/class-wc-table-rate-shipping.php:147 +#: includes/class-wc-table-rate-shipping.php:176 msgid "Premium Support" msgstr "" -#: includes/class-wc-table-rate-shipping.php:167 +#: includes/class-wc-table-rate-shipping.php:196 msgid "Order" msgstr "" -#: includes/class-wc-table-rate-shipping.php:168 +#: includes/class-wc-table-rate-shipping.php:197 msgid "Item" msgstr "" -#: includes/class-wc-table-rate-shipping.php:169 +#: includes/class-wc-table-rate-shipping.php:198 msgid "Line Item" msgstr "" -#: includes/class-wc-table-rate-shipping.php:170 +#: includes/class-wc-table-rate-shipping.php:199 #: includes/functions-admin.php:167 msgid "Class" msgstr "" -#: includes/class-wc-table-rate-shipping.php:171 +#: includes/class-wc-table-rate-shipping.php:200 msgid "Delete the selected rates?" msgstr "" -#: includes/class-wc-table-rate-shipping.php:172 +#: includes/class-wc-table-rate-shipping.php:201 msgid "Duplicate the selected rates?" msgstr "" -#: includes/class-wc-table-rate-shipping.php:221 +#: includes/class-wc-table-rate-shipping.php:250 #. translators: %s: WooCommerce link msgid "WooCommerce Table Rate Shipping requires %s to be installed and active." msgstr "" diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..bdb5fd2 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,45 @@ +/** + * The Webpack configuration for WooCommerce Table Rate Shipping. + * + * @package WooCommerce_Table_Rate_Shipping + */ + +const path = require( 'path' ); +const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); + +const config = { + ...defaultConfig, + entry: { + 'woocommerce-trs-abort-notices': + path.resolve( + process.cwd(), + 'client', + 'abort-notices', + 'index.js' + ), + }, + output: { + path: path.resolve( __dirname, 'dist' ), + filename: '[name].js', + }, + module: { + rules: [ + { + test: /\.(j|t)sx?$/, + exclude: [ /node_modules/ ], + loader: 'babel-loader', + } + ], + } +}; + +module.exports = ( env ) => { + if ( env.mode == 'production' ) { + config.mode = 'production'; + config.devtool = false; + } else { + config.mode = 'development'; + config.devtool = 'inline-source-map'; + } + return config; +}; diff --git a/woocommerce-table-rate-shipping.php b/woocommerce-table-rate-shipping.php index 7e84f94..4db2b28 100644 --- a/woocommerce-table-rate-shipping.php +++ b/woocommerce-table-rate-shipping.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce Table Rate Shipping * Plugin URI: https://woocommerce.com/products/table-rate-shipping/ * Description: Table rate shipping lets you define rates depending on location vs shipping class, price, weight, or item count. - * Version: 3.1.9 + * Version: 3.2.0 * Author: WooCommerce * Author URI: https://woocommerce.com/ * Text Domain: woocommerce-table-rate-shipping @@ -13,8 +13,8 @@ * Domain Path: /languages * Requires Plugins: woocommerce * Tested up to: 6.5 - * WC tested up to: 8.7 - * WC requires at least: 8.5 + * WC tested up to: 8.9 + * WC requires at least: 8.7 * * Woo: 18718:3034ed8aff427b0f635fe4c86bbf008a * @@ -26,7 +26,7 @@ } if ( ! defined( 'TABLE_RATE_SHIPPING_VERSION' ) ) { - define( 'TABLE_RATE_SHIPPING_VERSION', '3.1.9' ); // WRCS: DEFINED_VERSION. + define( 'TABLE_RATE_SHIPPING_VERSION', '3.2.0' ); // WRCS: DEFINED_VERSION. } if ( ! defined( 'TABLE_RATE_SHIPPING_DEBUG' ) ) { @@ -42,6 +42,22 @@ define( 'WC_TABLE_RATE_SHIPPING_MAIN_ABSPATH', dirname( WC_TABLE_RATE_SHIPPING_MAIN_FILE ) . '/' ); } +if ( ! defined( 'WC_TABLE_RATE_SHIPPING_PLUGIN_DIR' ) ) { + define( 'WC_TABLE_RATE_SHIPPING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); +} + +if ( ! defined( 'WC_TABLE_RATE_SHIPPING_PLUGIN_URL' ) ) { + define( 'WC_TABLE_RATE_SHIPPING_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); +} + +if ( ! defined( 'WC_TABLE_RATE_SHIPPING_DIST_DIR' ) ) { + define( 'WC_TABLE_RATE_SHIPPING_DIST_DIR', WC_TABLE_RATE_SHIPPING_PLUGIN_DIR . 'dist/' ); +} + +if ( ! defined( 'WC_TABLE_RATE_SHIPPING_DIST_URL' ) ) { + define( 'WC_TABLE_RATE_SHIPPING_DIST_URL', WC_TABLE_RATE_SHIPPING_PLUGIN_URL . 'dist/' ); +} + // Require the main Shipping Per Product class. if ( ! class_exists( 'WC_Table_Rate_Shipping' ) ) { require_once dirname( WC_TABLE_RATE_SHIPPING_MAIN_FILE ) . '/includes/class-wc-table-rate-shipping.php';