Changeset 3841382
- Timestamp:
- 12/03/2026 12:31:58 AM (less than one hour ago)
- Location:
- reachzone
- Files:
-
- 22 added
- 14 edited
- 1 copied
-
tags/0.3.0 (copied) (copied from reachzone/trunk )
-
tags/0.3.0/assets/css/checker.css (modified) (1 diff)
-
tags/0.3.0/blocks/checker/block.json (modified) (1 diff)
-
tags/0.3.0/blocks/checker/editor.js (modified) (3 diffs)
-
tags/0.3.0/includes/class-checker.php (modified) (5 diffs)
-
tags/0.3.0/includes/class-i18n.php (added)
-
tags/0.3.0/languages/reachzone-de_DE.mo (added)
-
tags/0.3.0/languages/reachzone-de_DE.po (added)
-
tags/0.3.0/languages/reachzone-es_ES.mo (added)
-
tags/0.3.0/languages/reachzone-es_ES.po (added)
-
tags/0.3.0/languages/reachzone-fr_FR.mo (added)
-
tags/0.3.0/languages/reachzone-fr_FR.po (added)
-
tags/0.3.0/languages/reachzone-it_IT.mo (added)
-
tags/0.3.0/languages/reachzone-it_IT.po (added)
-
tags/0.3.0/languages/reachzone-nl_NL.mo (added)
-
tags/0.3.0/languages/reachzone-nl_NL.po (added)
-
tags/0.3.0/languages/reachzone.pot (modified) (3 diffs)
-
tags/0.3.0/reachzone.php (modified) (3 diffs)
-
tags/0.3.0/readme.txt (modified) (5 diffs)
-
trunk/assets/css/checker.css (modified) (1 diff)
-
trunk/blocks/checker/block.json (modified) (1 diff)
-
trunk/blocks/checker/editor.js (modified) (3 diffs)
-
trunk/includes/class-checker.php (modified) (5 diffs)
-
trunk/includes/class-i18n.php (added)
-
trunk/languages/reachzone-de_DE.mo (added)
-
trunk/languages/reachzone-de_DE.po (added)
-
trunk/languages/reachzone-es_ES.mo (added)
-
trunk/languages/reachzone-es_ES.po (added)
-
trunk/languages/reachzone-fr_FR.mo (added)
-
trunk/languages/reachzone-fr_FR.po (added)
-
trunk/languages/reachzone-it_IT.mo (added)
-
trunk/languages/reachzone-it_IT.po (added)
-
trunk/languages/reachzone-nl_NL.mo (added)
-
trunk/languages/reachzone-nl_NL.po (added)
-
trunk/languages/reachzone.pot (modified) (3 diffs)
-
trunk/reachzone.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
reachzone/tags/0.3.0/assets/css/checker.css
r3785752 r3841382 13 13 .reachzone-result--out p { border-color: #b32d2e; } 14 14 .reachzone-result--unknown p, .reachzone-result--error p { border-color: #996800; } 15 /* Optional accent colour (block / shortcode "accent"): only set when the shop chose one. */ 16 .reachzone-checker--accent .reachzone-button { background: var(--reachzone-accent); border-color: var(--reachzone-accent); color: var(--reachzone-accent-text); } 17 .reachzone-checker--accent .reachzone-input:focus { border-color: var(--reachzone-accent); outline-color: var(--reachzone-accent); } -
reachzone/tags/0.3.0/blocks/checker/block.json
r3785752 r3841382 11 11 "textdomain": "reachzone", 12 12 "attributes": { 13 "title": { "type": "string", "default": "" } 13 "title": { "type": "string", "default": "" }, 14 "buttonText": { "type": "string", "default": "" }, 15 "accentColor": { "type": "string", "default": "" } 14 16 }, 15 17 "supports": { "html": false, "align": [ "wide", "full" ] }, -
reachzone/tags/0.3.0/blocks/checker/editor.js
r3785752 r3841382 7 7 var PanelBody = wp.components.PanelBody; 8 8 var TextControl = wp.components.TextControl; 9 var BaseControl = wp.components.BaseControl; 10 var ColorPalette = wp.components.ColorPalette; 11 // A few neutral choices; the picker also takes any colour. The shortcode attribute "accent" takes the same #rrggbb value. 12 var ACCENT_COLORS = [ 13 { name: 'Navy', color: '#2b4c7e' }, 14 { name: 'Green', color: '#1a7f37' }, 15 { name: 'Red', color: '#b32d2e' }, 16 { name: 'Marigold', color: '#f4b942' }, 17 { name: 'Ink', color: '#1e1e1e' } 18 ]; 9 19 10 20 wp.blocks.registerBlockType( 'reachzone/checker', { … … 12 22 var blockProps = useBlockProps( { className: 'reachzone-checker-preview' } ); 13 23 var title = props.attributes.title; 24 var buttonText = props.attributes.buttonText; 25 var accent = props.attributes.accentColor; 14 26 return el( 15 27 'div', … … 23 35 props.setAttributes( { title: v } ); 24 36 } 25 } ) 37 } ), 38 el( TextControl, { 39 label: __( 'Button text (optional)', 'reachzone' ), 40 help: __( 'Leave empty for "Check".', 'reachzone' ), 41 value: buttonText, 42 maxLength: 40, 43 onChange: function ( v ) { 44 props.setAttributes( { buttonText: v } ); 45 } 46 } ), 47 el( BaseControl, { label: __( 'Button colour (optional)', 'reachzone' ), __nextHasNoMarginBottom: true }, 48 el( ColorPalette, { 49 colors: ACCENT_COLORS, 50 value: accent || undefined, 51 clearable: true, 52 onChange: function ( v ) { 53 props.setAttributes( { accentColor: v || '' } ); 54 } 55 } ) 56 ) 26 57 ) 27 58 ), -
reachzone/tags/0.3.0/includes/class-checker.php
r3816841 r3841382 68 68 */ 69 69 public static function render_block( $attributes ) { 70 return self::render( isset( $attributes['title'] ) ? (string) $attributes['title'] : '' ); 71 } 72 73 /** 74 * Shortcode handler. 70 return self::render( 71 isset( $attributes['title'] ) ? (string) $attributes['title'] : '', 72 isset( $attributes['buttonText'] ) ? (string) $attributes['buttonText'] : '', 73 isset( $attributes['accentColor'] ) ? (string) $attributes['accentColor'] : '' 74 ); 75 } 76 77 /** 78 * Shortcode handler: [reachzone_checker title="Do we deliver?" button="Check" accent="#2b4c7e"]. 75 79 * 76 80 * @param array|string $atts Attributes. … … 78 82 */ 79 83 public static function shortcode( $atts ) { 80 $atts = shortcode_atts( array( 'title' => '' ), (array) $atts, self::SHORTCODE ); 81 return self::render( $atts['title'] ); 84 $atts = shortcode_atts( 85 array( 86 'title' => '', 87 'button' => '', 88 'accent' => '', 89 ), 90 (array) $atts, 91 self::SHORTCODE 92 ); 93 return self::render( $atts['title'], $atts['button'], $atts['accent'] ); 94 } 95 96 /** 97 * Button label from the block or shortcode: plain text, at most 40 characters. Empty means the default "Check". 98 * 99 * @param mixed $value Raw value. 100 * @return string 101 */ 102 public static function button_text( $value ) { 103 $text = is_string( $value ) ? trim( sanitize_text_field( $value ) ) : ''; 104 return function_exists( 'mb_substr' ) ? mb_substr( $text, 0, 40 ) : substr( $text, 0, 40 ); 105 } 106 107 /** 108 * Accent colour from the block or shortcode: a #rgb or #rrggbb value, lower-cased and expanded to six digits. 109 * Anything else (names, functions, injected CSS) is refused, so the value is safe in a style attribute. 110 * 111 * @param mixed $value Raw value. 112 * @return string The colour, or '' when absent or invalid. 113 */ 114 public static function accent_color( $value ) { 115 if ( ! is_string( $value ) || ! preg_match( '/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', trim( $value ), $m ) ) { 116 return ''; 117 } 118 $hex = strtolower( $m[1] ); 119 if ( 3 === strlen( $hex ) ) { 120 $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; 121 } 122 return '#' . $hex; 123 } 124 125 /** 126 * Readable text colour (black or white) on top of an accent colour, by WCAG relative luminance. 127 * 128 * @param string $hex Colour from accent_color(). 129 * @return string #000000 or #ffffff. 130 */ 131 public static function accent_text_color( $hex ) { 132 $lum = 0.0; 133 foreach ( array( array( 1, 0.2126 ), array( 3, 0.7152 ), array( 5, 0.0722 ) ) as $channel ) { 134 $c = hexdec( substr( $hex, $channel[0], 2 ) ) / 255; 135 $lum += $channel[1] * ( $c <= 0.03928 ? $c / 12.92 : pow( ( $c + 0.055 ) / 1.055, 2.4 ) ); 136 } 137 return $lum > 0.179 ? '#000000' : '#ffffff'; 82 138 } 83 139 … … 102 158 * Markup of the checker. 103 159 * 104 * @param string $title Optional heading. 105 * @return string 106 */ 107 public static function render( $title = '' ) { 160 * @param string $title Optional heading. 161 * @param string $button Optional button label (default "Check"). 162 * @param string $accent Optional accent colour for the button, #rgb or #rrggbb. 163 * @return string 164 */ 165 public static function render( $title = '', $button = '', $accent = '' ) { 108 166 if ( ! Settings::has_zones() ) { 109 167 return current_user_can( 'manage_woocommerce' ) … … 121 179 $uid = wp_unique_id( 'reachzone-input-' ); 122 180 $label = 'address' === $mode ? __( 'Your delivery address', 'reachzone' ) : __( 'Your postcode', 'reachzone' ); 181 $check = self::button_text( $button ); 182 $check = '' !== $check ? $check : __( 'Check', 'reachzone' ); 183 $color = self::accent_color( $accent ); 184 $class = 'reachzone-checker'; 185 $style = ''; 186 if ( '' !== $color ) { 187 $class .= ' reachzone-checker--accent'; 188 $style = ' style="--reachzone-accent:' . esc_attr( $color ) . ';--reachzone-accent-text:' . esc_attr( self::accent_text_color( $color ) ) . '"'; 189 } 123 190 ob_start(); 124 191 ?> 125 <div class=" reachzone-checker" data-reachzone-checker data-mode="<?php echo esc_attr( $mode ); ?>">192 <div class="<?php echo esc_attr( $class ); ?>" data-reachzone-checker data-mode="<?php echo esc_attr( $mode ); ?>"<?php echo $style; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built from esc_attr() values above. ?>> 126 193 <?php if ( '' !== $title ) : ?> 127 194 <h3 class="reachzone-title"><?php echo esc_html( $title ); ?></h3> … … 132 199 <div class="reachzone-row"> 133 200 <input class="reachzone-input" id="<?php echo esc_attr( $uid ); ?>" type="text" name="reachzone_query" autocomplete="<?php echo 'address' === $mode ? 'street-address' : 'postal-code'; ?>" maxlength="300" required /> 134 <button type="submit" class="reachzone-button wp-element-button"><?php e sc_html_e( 'Check', 'reachzone'); ?></button>201 <button type="submit" class="reachzone-button wp-element-button"><?php echo esc_html( $check ); ?></button> 135 202 </div> 136 203 <?php endif; ?> -
reachzone/tags/0.3.0/languages/reachzone.pot
r3816841 r3841382 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2026-1 1-22T16:01:04+00:00\n"12 "POT-Creation-Date: 2026-12-03T00:21:55+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.12.0\n" … … 497 497 msgstr "" 498 498 499 #: includes/class-checker.php:1 10499 #: includes/class-checker.php:168 500 500 msgid "ReachZone: add a delivery zone under WooCommerce > ReachZone to show the checker." 501 501 msgstr "" 502 502 503 #: includes/class-checker.php:1 22503 #: includes/class-checker.php:180 504 504 msgid "Your delivery address" 505 505 msgstr "" 506 506 507 #: includes/class-checker.php:1 22507 #: includes/class-checker.php:180 508 508 msgid "Your postcode" 509 509 msgstr "" 510 510 511 #: includes/class-checker.php:1 34511 #: includes/class-checker.php:182 512 512 msgid "Check" 513 513 msgstr "" 514 514 515 #: includes/class-checker.php: 139515 #: includes/class-checker.php:206 516 516 msgid "Use my current location" 517 517 msgstr "" 518 518 519 #: includes/class-checker.php: 140519 #: includes/class-checker.php:207 520 520 msgid "Optional. Your browser will ask for permission. The position is used only to check our delivery area." 521 521 msgstr "" 522 522 523 #: includes/class-checker.php: 183523 #: includes/class-checker.php:250 524 524 msgid "free delivery" 525 525 msgstr "" 526 526 527 527 #. translators: %s: delivery fee, for example $4.99 528 #: includes/class-checker.php: 186528 #: includes/class-checker.php:253 529 529 #, php-format 530 530 msgid "%s delivery fee" 531 531 msgstr "" 532 532 533 #: includes/class-checker.php:2 21534 #: includes/class-checker.php: 395533 #: includes/class-checker.php:288 534 #: includes/class-checker.php:462 535 535 msgid "Please enter your postcode or use your current location so we can check our delivery area." 536 536 msgstr "" 537 537 538 #: includes/class-checker.php:2 22539 #: includes/class-checker.php:3 06538 #: includes/class-checker.php:289 539 #: includes/class-checker.php:373 540 540 msgid "We could not find that address. Please check it and try again." 541 541 msgstr "" 542 542 543 #: includes/class-checker.php:2 23544 #: includes/class-checker.php:3 07543 #: includes/class-checker.php:290 544 #: includes/class-checker.php:374 545 545 msgid "Sorry, the check did not work. Please try again in a moment." 546 546 msgstr "" 547 547 548 #: includes/class-checker.php:2 24548 #: includes/class-checker.php:291 549 549 msgid "Checking..." 550 550 msgstr "" 551 551 552 #: includes/class-checker.php:2 25552 #: includes/class-checker.php:292 553 553 msgid "We could not get your location. You can type your address or postcode instead." 554 554 msgstr "" 555 555 556 #: includes/class-checker.php:2 26556 #: includes/class-checker.php:293 557 557 msgid "Your browser does not support location sharing." 558 558 msgstr "" 559 559 560 #: includes/class-checker.php:2 27560 #: includes/class-checker.php:294 561 561 msgid "Please enter an address or postcode first." 562 562 msgstr "" 563 563 564 #: includes/class-checker.php: 281564 #: includes/class-checker.php:348 565 565 msgid "Too many checks. Please wait a few minutes." 566 566 msgstr "" 567 567 568 #: includes/class-checker.php: 285568 #: includes/class-checker.php:352 569 569 msgid "Invalid input." 570 570 msgstr "" 571 571 572 #: includes/class-checker.php: 297572 #: includes/class-checker.php:364 573 573 msgid "Address lookup is not available in this shop." 574 574 msgstr "" 575 575 576 #: includes/class-checker.php:3 01576 #: includes/class-checker.php:368 577 577 msgid "Please enter an address." 578 578 msgstr "" 579 579 580 #: includes/class-checker.php:3 15580 #: includes/class-checker.php:382 581 581 msgid "Invalid position." 582 582 msgstr "" … … 707 707 msgstr "" 708 708 709 #: reachzone.php:6 4709 #: reachzone.php:67 710 710 msgid "ReachZone needs WooCommerce to be installed and active." 711 711 msgstr "" 712 712 713 #: blocks/checker/editor.js: 18713 #: blocks/checker/editor.js:30 714 714 msgid "Delivery checker" 715 715 msgstr "" 716 716 717 #: blocks/checker/editor.js: 20717 #: blocks/checker/editor.js:32 718 718 msgid "Heading (optional)" 719 719 msgstr "" 720 720 721 #: blocks/checker/editor.js:29 721 #: blocks/checker/editor.js:39 722 msgid "Button text (optional)" 723 msgstr "" 724 725 #: blocks/checker/editor.js:40 726 msgid "Leave empty for \"Check\"." 727 msgstr "" 728 729 #: blocks/checker/editor.js:47 730 msgid "Button colour (optional)" 731 msgstr "" 732 733 #: blocks/checker/editor.js:60 722 734 msgid "Delivery checker: shoppers enter their address or postcode, or share their location. Zones are set under WooCommerce > ReachZone." 723 735 msgstr "" -
reachzone/tags/0.3.0/reachzone.php
r3816841 r3841382 4 4 * Plugin URI: https://reachzone.app 5 5 * Description: Let shoppers check if you deliver to them, and enforce delivery zones, fees and minimum orders at checkout. Radius, drawn-area, postcode and drive-time zones. 6 * Version: 0. 2.06 * Version: 0.3.0 7 7 * Requires at least: 6.2 8 8 * Requires PHP: 7.4 … … 19 19 defined( 'ABSPATH' ) || exit; 20 20 21 define( 'REACHZONE_VERSION', '0. 2.0' );21 define( 'REACHZONE_VERSION', '0.3.0' ); 22 22 define( 'REACHZONE_FILE', __FILE__ ); 23 23 define( 'REACHZONE_DIR', plugin_dir_path( __FILE__ ) ); 24 24 define( 'REACHZONE_URL', plugin_dir_url( __FILE__ ) ); 25 25 26 require_once REACHZONE_DIR . 'includes/class-i18n.php'; 26 27 require_once REACHZONE_DIR . 'includes/class-geometry.php'; 27 28 require_once REACHZONE_DIR . 'includes/class-zones.php'; … … 39 40 require_once REACHZONE_DIR . 'includes/class-addon-promo.php'; 40 41 require_once REACHZONE_DIR . 'includes/class-admin.php'; 42 43 ReachZone\I18n::init(); 41 44 42 45 register_activation_hook( __FILE__, array( 'ReachZone\Demand', 'install' ) ); -
reachzone/tags/0.3.0/readme.txt
r3826550 r3841382 6 6 Requires PHP: 7.4 7 7 Requires Plugins: woocommerce 8 Stable tag: 0. 2.08 Stable tag: 0.3.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 20 20 * **Zones on a map.** Unlimited locations, each with radius zones (km or miles), areas you draw on the map, or lists of postcodes or ZIP codes (exact, prefix such as `606*`, ranges such as `60601-60610`, UK outward codes and Canadian FSAs). 21 21 * **Per-zone rules.** Delivery fee, minimum order, delivery time text and which WooCommerce shipping methods are allowed. 22 * **Delivery checker.** A block and a `[reachzone_checker]` shortcode. Shoppers see "We deliver here: 30 min, $4.99" or "Outside our delivery area" before they fill a cart. 22 * **Delivery checker.** A block and a `[reachzone_checker]` shortcode. Shoppers see "We deliver here: 30 min, $4.99" or "Outside our delivery area" before they fill a cart. Set your own heading, button text and button colour (`[reachzone_checker title="Do we deliver?" button="Check" accent="#2b4c7e"]`). 23 * **Shoppers in their language.** The checker and the checkout messages ship in German, French, Italian, Dutch and Spanish, and follow your site language. 23 24 * **Checkout rules.** The matching zone filters shipping methods, adds its fee, enforces its minimum order, and blocks checkout outside every zone. Works with the classic checkout and the block checkout. 24 25 * **Shoppers outside your zones.** The settings page shows how many shoppers were turned away this month because their address is outside every zone, so you can see what a bigger area would bring. … … 143 144 Out-of-zone orders are blocked and the Store API rejects them. Fee and minimum order are applied through the cart, and shipping methods are filtered in the same way as in classic checkout. The delivery option shows the zone's delivery time, for example "Delivery (30 min)". The unserved-demand map (Business and Agency plans, opt-in) is fed from the block checkout too, once per shopper and rounded spot per hour. 144 145 146 = Is the checker translated? = 147 148 Yes. The delivery checker and the checkout messages ship in German, French, Italian, Dutch and Spanish, and follow your site language (regional variants such as de_CH or es_MX use the main translation). Messages you write yourself in the settings are shown as you wrote them. Translations from translate.wordpress.org are welcome and take priority. 149 145 150 = Does it work with Indian PIN codes (pincodes)? = 146 151 … … 164 169 == Changelog == 165 170 171 = 0.3.0 = 172 * The delivery checker and the checkout messages are translated into German, French, Italian, Dutch and Spanish (bundled; a WordPress.org language pack, when there is one, comes first). 173 * Checker block and shortcode: your own button text and button colour (shortcode attributes `button` and `accent`). 174 166 175 = 0.2.0 = 167 176 * The settings page shows how many shoppers were outside your zones this month (counted once per shopper; no address is kept). … … 181 190 == Upgrade Notice == 182 191 192 = 0.3.0 = 193 The checker and checkout messages now speak German, French, Italian, Dutch and Spanish. New button text and colour options for the checker. 194 183 195 = 0.2.0 = 184 196 Adds a "Shoppers outside your zones this month" count to the settings page, and the hooks the Delivery Slots add-on needs for delivery hours. -
reachzone/trunk/assets/css/checker.css
r3785752 r3841382 13 13 .reachzone-result--out p { border-color: #b32d2e; } 14 14 .reachzone-result--unknown p, .reachzone-result--error p { border-color: #996800; } 15 /* Optional accent colour (block / shortcode "accent"): only set when the shop chose one. */ 16 .reachzone-checker--accent .reachzone-button { background: var(--reachzone-accent); border-color: var(--reachzone-accent); color: var(--reachzone-accent-text); } 17 .reachzone-checker--accent .reachzone-input:focus { border-color: var(--reachzone-accent); outline-color: var(--reachzone-accent); } -
reachzone/trunk/blocks/checker/block.json
r3785752 r3841382 11 11 "textdomain": "reachzone", 12 12 "attributes": { 13 "title": { "type": "string", "default": "" } 13 "title": { "type": "string", "default": "" }, 14 "buttonText": { "type": "string", "default": "" }, 15 "accentColor": { "type": "string", "default": "" } 14 16 }, 15 17 "supports": { "html": false, "align": [ "wide", "full" ] }, -
reachzone/trunk/blocks/checker/editor.js
r3785752 r3841382 7 7 var PanelBody = wp.components.PanelBody; 8 8 var TextControl = wp.components.TextControl; 9 var BaseControl = wp.components.BaseControl; 10 var ColorPalette = wp.components.ColorPalette; 11 // A few neutral choices; the picker also takes any colour. The shortcode attribute "accent" takes the same #rrggbb value. 12 var ACCENT_COLORS = [ 13 { name: 'Navy', color: '#2b4c7e' }, 14 { name: 'Green', color: '#1a7f37' }, 15 { name: 'Red', color: '#b32d2e' }, 16 { name: 'Marigold', color: '#f4b942' }, 17 { name: 'Ink', color: '#1e1e1e' } 18 ]; 9 19 10 20 wp.blocks.registerBlockType( 'reachzone/checker', { … … 12 22 var blockProps = useBlockProps( { className: 'reachzone-checker-preview' } ); 13 23 var title = props.attributes.title; 24 var buttonText = props.attributes.buttonText; 25 var accent = props.attributes.accentColor; 14 26 return el( 15 27 'div', … … 23 35 props.setAttributes( { title: v } ); 24 36 } 25 } ) 37 } ), 38 el( TextControl, { 39 label: __( 'Button text (optional)', 'reachzone' ), 40 help: __( 'Leave empty for "Check".', 'reachzone' ), 41 value: buttonText, 42 maxLength: 40, 43 onChange: function ( v ) { 44 props.setAttributes( { buttonText: v } ); 45 } 46 } ), 47 el( BaseControl, { label: __( 'Button colour (optional)', 'reachzone' ), __nextHasNoMarginBottom: true }, 48 el( ColorPalette, { 49 colors: ACCENT_COLORS, 50 value: accent || undefined, 51 clearable: true, 52 onChange: function ( v ) { 53 props.setAttributes( { accentColor: v || '' } ); 54 } 55 } ) 56 ) 26 57 ) 27 58 ), -
reachzone/trunk/includes/class-checker.php
r3816841 r3841382 68 68 */ 69 69 public static function render_block( $attributes ) { 70 return self::render( isset( $attributes['title'] ) ? (string) $attributes['title'] : '' ); 71 } 72 73 /** 74 * Shortcode handler. 70 return self::render( 71 isset( $attributes['title'] ) ? (string) $attributes['title'] : '', 72 isset( $attributes['buttonText'] ) ? (string) $attributes['buttonText'] : '', 73 isset( $attributes['accentColor'] ) ? (string) $attributes['accentColor'] : '' 74 ); 75 } 76 77 /** 78 * Shortcode handler: [reachzone_checker title="Do we deliver?" button="Check" accent="#2b4c7e"]. 75 79 * 76 80 * @param array|string $atts Attributes. … … 78 82 */ 79 83 public static function shortcode( $atts ) { 80 $atts = shortcode_atts( array( 'title' => '' ), (array) $atts, self::SHORTCODE ); 81 return self::render( $atts['title'] ); 84 $atts = shortcode_atts( 85 array( 86 'title' => '', 87 'button' => '', 88 'accent' => '', 89 ), 90 (array) $atts, 91 self::SHORTCODE 92 ); 93 return self::render( $atts['title'], $atts['button'], $atts['accent'] ); 94 } 95 96 /** 97 * Button label from the block or shortcode: plain text, at most 40 characters. Empty means the default "Check". 98 * 99 * @param mixed $value Raw value. 100 * @return string 101 */ 102 public static function button_text( $value ) { 103 $text = is_string( $value ) ? trim( sanitize_text_field( $value ) ) : ''; 104 return function_exists( 'mb_substr' ) ? mb_substr( $text, 0, 40 ) : substr( $text, 0, 40 ); 105 } 106 107 /** 108 * Accent colour from the block or shortcode: a #rgb or #rrggbb value, lower-cased and expanded to six digits. 109 * Anything else (names, functions, injected CSS) is refused, so the value is safe in a style attribute. 110 * 111 * @param mixed $value Raw value. 112 * @return string The colour, or '' when absent or invalid. 113 */ 114 public static function accent_color( $value ) { 115 if ( ! is_string( $value ) || ! preg_match( '/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', trim( $value ), $m ) ) { 116 return ''; 117 } 118 $hex = strtolower( $m[1] ); 119 if ( 3 === strlen( $hex ) ) { 120 $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; 121 } 122 return '#' . $hex; 123 } 124 125 /** 126 * Readable text colour (black or white) on top of an accent colour, by WCAG relative luminance. 127 * 128 * @param string $hex Colour from accent_color(). 129 * @return string #000000 or #ffffff. 130 */ 131 public static function accent_text_color( $hex ) { 132 $lum = 0.0; 133 foreach ( array( array( 1, 0.2126 ), array( 3, 0.7152 ), array( 5, 0.0722 ) ) as $channel ) { 134 $c = hexdec( substr( $hex, $channel[0], 2 ) ) / 255; 135 $lum += $channel[1] * ( $c <= 0.03928 ? $c / 12.92 : pow( ( $c + 0.055 ) / 1.055, 2.4 ) ); 136 } 137 return $lum > 0.179 ? '#000000' : '#ffffff'; 82 138 } 83 139 … … 102 158 * Markup of the checker. 103 159 * 104 * @param string $title Optional heading. 105 * @return string 106 */ 107 public static function render( $title = '' ) { 160 * @param string $title Optional heading. 161 * @param string $button Optional button label (default "Check"). 162 * @param string $accent Optional accent colour for the button, #rgb or #rrggbb. 163 * @return string 164 */ 165 public static function render( $title = '', $button = '', $accent = '' ) { 108 166 if ( ! Settings::has_zones() ) { 109 167 return current_user_can( 'manage_woocommerce' ) … … 121 179 $uid = wp_unique_id( 'reachzone-input-' ); 122 180 $label = 'address' === $mode ? __( 'Your delivery address', 'reachzone' ) : __( 'Your postcode', 'reachzone' ); 181 $check = self::button_text( $button ); 182 $check = '' !== $check ? $check : __( 'Check', 'reachzone' ); 183 $color = self::accent_color( $accent ); 184 $class = 'reachzone-checker'; 185 $style = ''; 186 if ( '' !== $color ) { 187 $class .= ' reachzone-checker--accent'; 188 $style = ' style="--reachzone-accent:' . esc_attr( $color ) . ';--reachzone-accent-text:' . esc_attr( self::accent_text_color( $color ) ) . '"'; 189 } 123 190 ob_start(); 124 191 ?> 125 <div class=" reachzone-checker" data-reachzone-checker data-mode="<?php echo esc_attr( $mode ); ?>">192 <div class="<?php echo esc_attr( $class ); ?>" data-reachzone-checker data-mode="<?php echo esc_attr( $mode ); ?>"<?php echo $style; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built from esc_attr() values above. ?>> 126 193 <?php if ( '' !== $title ) : ?> 127 194 <h3 class="reachzone-title"><?php echo esc_html( $title ); ?></h3> … … 132 199 <div class="reachzone-row"> 133 200 <input class="reachzone-input" id="<?php echo esc_attr( $uid ); ?>" type="text" name="reachzone_query" autocomplete="<?php echo 'address' === $mode ? 'street-address' : 'postal-code'; ?>" maxlength="300" required /> 134 <button type="submit" class="reachzone-button wp-element-button"><?php e sc_html_e( 'Check', 'reachzone'); ?></button>201 <button type="submit" class="reachzone-button wp-element-button"><?php echo esc_html( $check ); ?></button> 135 202 </div> 136 203 <?php endif; ?> -
reachzone/trunk/languages/reachzone.pot
r3816841 r3841382 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2026-1 1-22T16:01:04+00:00\n"12 "POT-Creation-Date: 2026-12-03T00:21:55+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.12.0\n" … … 497 497 msgstr "" 498 498 499 #: includes/class-checker.php:1 10499 #: includes/class-checker.php:168 500 500 msgid "ReachZone: add a delivery zone under WooCommerce > ReachZone to show the checker." 501 501 msgstr "" 502 502 503 #: includes/class-checker.php:1 22503 #: includes/class-checker.php:180 504 504 msgid "Your delivery address" 505 505 msgstr "" 506 506 507 #: includes/class-checker.php:1 22507 #: includes/class-checker.php:180 508 508 msgid "Your postcode" 509 509 msgstr "" 510 510 511 #: includes/class-checker.php:1 34511 #: includes/class-checker.php:182 512 512 msgid "Check" 513 513 msgstr "" 514 514 515 #: includes/class-checker.php: 139515 #: includes/class-checker.php:206 516 516 msgid "Use my current location" 517 517 msgstr "" 518 518 519 #: includes/class-checker.php: 140519 #: includes/class-checker.php:207 520 520 msgid "Optional. Your browser will ask for permission. The position is used only to check our delivery area." 521 521 msgstr "" 522 522 523 #: includes/class-checker.php: 183523 #: includes/class-checker.php:250 524 524 msgid "free delivery" 525 525 msgstr "" 526 526 527 527 #. translators: %s: delivery fee, for example $4.99 528 #: includes/class-checker.php: 186528 #: includes/class-checker.php:253 529 529 #, php-format 530 530 msgid "%s delivery fee" 531 531 msgstr "" 532 532 533 #: includes/class-checker.php:2 21534 #: includes/class-checker.php: 395533 #: includes/class-checker.php:288 534 #: includes/class-checker.php:462 535 535 msgid "Please enter your postcode or use your current location so we can check our delivery area." 536 536 msgstr "" 537 537 538 #: includes/class-checker.php:2 22539 #: includes/class-checker.php:3 06538 #: includes/class-checker.php:289 539 #: includes/class-checker.php:373 540 540 msgid "We could not find that address. Please check it and try again." 541 541 msgstr "" 542 542 543 #: includes/class-checker.php:2 23544 #: includes/class-checker.php:3 07543 #: includes/class-checker.php:290 544 #: includes/class-checker.php:374 545 545 msgid "Sorry, the check did not work. Please try again in a moment." 546 546 msgstr "" 547 547 548 #: includes/class-checker.php:2 24548 #: includes/class-checker.php:291 549 549 msgid "Checking..." 550 550 msgstr "" 551 551 552 #: includes/class-checker.php:2 25552 #: includes/class-checker.php:292 553 553 msgid "We could not get your location. You can type your address or postcode instead." 554 554 msgstr "" 555 555 556 #: includes/class-checker.php:2 26556 #: includes/class-checker.php:293 557 557 msgid "Your browser does not support location sharing." 558 558 msgstr "" 559 559 560 #: includes/class-checker.php:2 27560 #: includes/class-checker.php:294 561 561 msgid "Please enter an address or postcode first." 562 562 msgstr "" 563 563 564 #: includes/class-checker.php: 281564 #: includes/class-checker.php:348 565 565 msgid "Too many checks. Please wait a few minutes." 566 566 msgstr "" 567 567 568 #: includes/class-checker.php: 285568 #: includes/class-checker.php:352 569 569 msgid "Invalid input." 570 570 msgstr "" 571 571 572 #: includes/class-checker.php: 297572 #: includes/class-checker.php:364 573 573 msgid "Address lookup is not available in this shop." 574 574 msgstr "" 575 575 576 #: includes/class-checker.php:3 01576 #: includes/class-checker.php:368 577 577 msgid "Please enter an address." 578 578 msgstr "" 579 579 580 #: includes/class-checker.php:3 15580 #: includes/class-checker.php:382 581 581 msgid "Invalid position." 582 582 msgstr "" … … 707 707 msgstr "" 708 708 709 #: reachzone.php:6 4709 #: reachzone.php:67 710 710 msgid "ReachZone needs WooCommerce to be installed and active." 711 711 msgstr "" 712 712 713 #: blocks/checker/editor.js: 18713 #: blocks/checker/editor.js:30 714 714 msgid "Delivery checker" 715 715 msgstr "" 716 716 717 #: blocks/checker/editor.js: 20717 #: blocks/checker/editor.js:32 718 718 msgid "Heading (optional)" 719 719 msgstr "" 720 720 721 #: blocks/checker/editor.js:29 721 #: blocks/checker/editor.js:39 722 msgid "Button text (optional)" 723 msgstr "" 724 725 #: blocks/checker/editor.js:40 726 msgid "Leave empty for \"Check\"." 727 msgstr "" 728 729 #: blocks/checker/editor.js:47 730 msgid "Button colour (optional)" 731 msgstr "" 732 733 #: blocks/checker/editor.js:60 722 734 msgid "Delivery checker: shoppers enter their address or postcode, or share their location. Zones are set under WooCommerce > ReachZone." 723 735 msgstr "" -
reachzone/trunk/reachzone.php
r3816841 r3841382 4 4 * Plugin URI: https://reachzone.app 5 5 * Description: Let shoppers check if you deliver to them, and enforce delivery zones, fees and minimum orders at checkout. Radius, drawn-area, postcode and drive-time zones. 6 * Version: 0. 2.06 * Version: 0.3.0 7 7 * Requires at least: 6.2 8 8 * Requires PHP: 7.4 … … 19 19 defined( 'ABSPATH' ) || exit; 20 20 21 define( 'REACHZONE_VERSION', '0. 2.0' );21 define( 'REACHZONE_VERSION', '0.3.0' ); 22 22 define( 'REACHZONE_FILE', __FILE__ ); 23 23 define( 'REACHZONE_DIR', plugin_dir_path( __FILE__ ) ); 24 24 define( 'REACHZONE_URL', plugin_dir_url( __FILE__ ) ); 25 25 26 require_once REACHZONE_DIR . 'includes/class-i18n.php'; 26 27 require_once REACHZONE_DIR . 'includes/class-geometry.php'; 27 28 require_once REACHZONE_DIR . 'includes/class-zones.php'; … … 39 40 require_once REACHZONE_DIR . 'includes/class-addon-promo.php'; 40 41 require_once REACHZONE_DIR . 'includes/class-admin.php'; 42 43 ReachZone\I18n::init(); 41 44 42 45 register_activation_hook( __FILE__, array( 'ReachZone\Demand', 'install' ) ); -
reachzone/trunk/readme.txt
r3826550 r3841382 6 6 Requires PHP: 7.4 7 7 Requires Plugins: woocommerce 8 Stable tag: 0. 2.08 Stable tag: 0.3.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 20 20 * **Zones on a map.** Unlimited locations, each with radius zones (km or miles), areas you draw on the map, or lists of postcodes or ZIP codes (exact, prefix such as `606*`, ranges such as `60601-60610`, UK outward codes and Canadian FSAs). 21 21 * **Per-zone rules.** Delivery fee, minimum order, delivery time text and which WooCommerce shipping methods are allowed. 22 * **Delivery checker.** A block and a `[reachzone_checker]` shortcode. Shoppers see "We deliver here: 30 min, $4.99" or "Outside our delivery area" before they fill a cart. 22 * **Delivery checker.** A block and a `[reachzone_checker]` shortcode. Shoppers see "We deliver here: 30 min, $4.99" or "Outside our delivery area" before they fill a cart. Set your own heading, button text and button colour (`[reachzone_checker title="Do we deliver?" button="Check" accent="#2b4c7e"]`). 23 * **Shoppers in their language.** The checker and the checkout messages ship in German, French, Italian, Dutch and Spanish, and follow your site language. 23 24 * **Checkout rules.** The matching zone filters shipping methods, adds its fee, enforces its minimum order, and blocks checkout outside every zone. Works with the classic checkout and the block checkout. 24 25 * **Shoppers outside your zones.** The settings page shows how many shoppers were turned away this month because their address is outside every zone, so you can see what a bigger area would bring. … … 143 144 Out-of-zone orders are blocked and the Store API rejects them. Fee and minimum order are applied through the cart, and shipping methods are filtered in the same way as in classic checkout. The delivery option shows the zone's delivery time, for example "Delivery (30 min)". The unserved-demand map (Business and Agency plans, opt-in) is fed from the block checkout too, once per shopper and rounded spot per hour. 144 145 146 = Is the checker translated? = 147 148 Yes. The delivery checker and the checkout messages ship in German, French, Italian, Dutch and Spanish, and follow your site language (regional variants such as de_CH or es_MX use the main translation). Messages you write yourself in the settings are shown as you wrote them. Translations from translate.wordpress.org are welcome and take priority. 149 145 150 = Does it work with Indian PIN codes (pincodes)? = 146 151 … … 164 169 == Changelog == 165 170 171 = 0.3.0 = 172 * The delivery checker and the checkout messages are translated into German, French, Italian, Dutch and Spanish (bundled; a WordPress.org language pack, when there is one, comes first). 173 * Checker block and shortcode: your own button text and button colour (shortcode attributes `button` and `accent`). 174 166 175 = 0.2.0 = 167 176 * The settings page shows how many shoppers were outside your zones this month (counted once per shopper; no address is kept). … … 181 190 == Upgrade Notice == 182 191 192 = 0.3.0 = 193 The checker and checkout messages now speak German, French, Italian, Dutch and Spanish. New button text and colour options for the checker. 194 183 195 = 0.2.0 = 184 196 Adds a "Shoppers outside your zones this month" count to the settings page, and the hooks the Delivery Slots add-on needs for delivery hours.
Note:
See TracChangeset
for help on using the changeset viewer.