Compare commits

..

5 Commits

Author SHA1 Message Date
Remo Zaros
41f44b1200 Add more postcode ranges 2026-05-18 18:42:26 +02:00
Remo Zaros
7f32a4bb1b Add new styles 2026-05-18 18:41:52 +02:00
Remo Zaros
492289deb1 session changed, css, postcode range 2026-05-18 10:17:45 +02:00
Remo Zaros
318eb8f0c5 Change postcode modal. 2026-05-17 16:44:57 +02:00
Remo Zaros
6fd3f4a13c Add dropdown filter. Add label rename variable products admin 2026-05-14 15:04:55 +02:00
3 changed files with 144 additions and 60 deletions

View File

@@ -1,47 +1,67 @@
.postcode_modal { .postcode_modal {
border-radius: 20px; border-radius: 3px;
box-shadow(10px);
border: none; border: none;
max-width: 80ch; max-width: 65ch;
box-shadow: 0 0 20pc black;
padding: 2rem; padding: 2rem;
padding-bottom: 1rem;
opacity: 0; opacity: 0;
transition: opacity 0.3s ease, display 0.3s allow-discrete; transition:
opacity 0.3s ease,
display 0.3s allow-discrete;
&[open] { &[open] {
opacity: 1; opacity: 1;
transition-behavior: allow-discrete; transition-behavior: allow-discrete;
transition: opacity 0.3s ease, display 0.3s allow-discrete; transition:
} opacity 0.3s ease,
display 0.3s allow-discrete;
&:not([open]) {
display: none;
} }
h2 { h2 {
font-size: 1.5rem; font-size: 1.1rem;
margin: .6rem; font-weight: 700;
}
p {
font-size: 1rem;
}
&:not([open]) {
display: none;
}
form {
margin-top: 1rem;
} }
input[type="text"] { input[type="text"] {
padding: .3rem; padding: 0.3rem;
font-size: 1.4rem; font-size: 1.2rem;
caret-color: hsl(344 98 40); caret-color: var(--wp--preset--color--vivid-red);
background: hsl(0 1 80);
border: none;
&:focus,
&:valid,
&:invalid,
&:autofill,
&:autofill:focus {
background: hsl(0 1 80) !important;
}
} }
button { button {
border: none; font-size: 1.2rem;
font-size: 1.4rem; font-weight: 700;
color: hsl(233 100 100); color: hsl(233 100 100);
padding: .4rem 1rem; padding: 0.4rem 1rem;
border-radius: 5px; background: var(--wp--preset--color--vivid-red);
background: hsl(344 98 40); border: 1px var(--wp--preset--color--vivid-red) solid;
border: 1px hsl(344 98 40) solid; margin: 0 0 0 0.3rem;
margin: 0 0 0 .3rem; transition: 0.2s all linear;
transition: .2s all linear; padding: 0.2em 2.5em;
&:hover {
&:hover{ color: var(--wp--preset--color--vivid-red);
color: hsl(344 98 40 );
background: hsl(344 98 100); background: hsl(344 98 100);
cursor: pointer; cursor: pointer;
} }
@@ -51,20 +71,19 @@
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
div {
&>{
display: flex; display: flex;
gap: 1.5rem;
} }
} }
&::backdrop { &::backdrop {
backdrop-filter: blur(1px); backdrop-filter: blur(2px);
background-color: hsl(40deg 100 0 /0.4); background: hsl(0 1 65 / 0.6);
background: radial-gradient(circle,rgba(33, 33, 33, 0.68) 0%, rgba(15, 15, 15, 0.8) 23%, rgba(0, 0, 0, 0.87) 100%);
} }
.error_message_modal_postcode { .error_message_modal_postcode {
min-height: 1lh; min-height: 1lh;
color: hsl(344 98 40 ); color: var(--wp--preset--color--vivid-red);
}/* HTML: <div class="loader"></div> */ } /* HTML: <div class="loader"></div> */
} }

View File

@@ -1,12 +1,11 @@
<?php <?php
session_start(); require_once plugin_dir_path(__FILE__) . "session_dialog.php";
require_once "session_dialog.php";
/* /*
* Plugin Name: prijzen per poscode range * Plugin Name: prijzen per poscode range
* Description: posctcodes in de 5000-5800 range krijgen een lokaal tarief aangeboden. * Description: posctcodes in de 5000-5800 range krijgen een lokaal tarief aangeboden.
* Author: Remo Zaros * Author: Remo Zaros
* Version: 0.9.1 * Version: 0.9.3
* Text Domeain: prijs-per-postcode * Text Domeain: prijs-per-postcode
*/ */
@@ -19,15 +18,19 @@ class PrijsPerPostcode
{ {
public function __construct() public function __construct()
{ {
add_action("init", [$this, "init"]); add_action("init", [$this, "init"], 1);
add_action("rest_api_init", "register_modal_api"); add_action("rest_api_init", "register_modal_api");
} }
public function init() public function init()
{ {
if (session_status() == PHP_SESSION_NONE) {
ob_start();
@session_start();
}
$uri = $_SERVER["REQUEST_URI"]; $uri = $_SERVER["REQUEST_URI"];
add_filter("woocommerce_sale_flash", "__return_null");
init_postcode_handlers($uri); init_postcode_handlers($uri);
add_filter("woocommerce_sale_flash", "__return_null");
//add_action("template_redirect", [$this, "redirect_if_missing_tag"]); //add_action("template_redirect", [$this, "redirect_if_missing_tag"]);
add_action( add_action(
@@ -57,6 +60,18 @@ class PrijsPerPostcode
$this, $this,
"controleer_postcode_op_woocommerce_paginas", "controleer_postcode_op_woocommerce_paginas",
]); ]);
add_filter(
"woocommerce_variation_is_visible",
[$this, "filter_variation_by_local_price"],
10,
4,
);
add_filter(
"gettext",
[$this, "change_variation_regular_price_label"],
99,
3,
);
} }
public function add_local_price_field($loop, $variation_data, $variation) public function add_local_price_field($loop, $variation_data, $variation)
@@ -155,6 +170,53 @@ class PrijsPerPostcode
} }
return $price_html; return $price_html;
} }
function filter_variation_by_local_price(
$visible,
$variation_id,
$parent_id,
$variation,
) {
// Ensure $variation is a valid object
if (!$variation instanceof WC_Product_Variation) {
$variation = wc_get_product($variation_id);
}
if (!$variation) {
return false;
}
$is_local = isset($_SESSION["postcode_is_local"])
? $_SESSION["postcode_is_local"]
: false;
$price = $is_local
? $variation->get_meta("_local_price", true)
: $variation->get_regular_price();
if (empty($price) || floatval($price) == 0) {
return false;
}
return $visible;
}
public function change_variation_regular_price_label(
$translated_text,
$text,
$domain,
) {
if (
"woocommerce" === $domain &&
is_admin() &&
isset($_REQUEST["action"]) &&
"woocommerce_load_variations" === $_REQUEST["action"]
) {
if ($translated_text === "Reguliere prijs (%s)") {
$translated_text = "Prijs overige regios (%s)";
}
}
return $translated_text;
}
} }
new PrijsPerPostcode(); new PrijsPerPostcode();

View File

@@ -106,30 +106,38 @@ function render_dialog_html()
?> ?>
<dialog id="postcode_modal" class="postcode_modal" closedby="none"> <dialog id="postcode_modal" class="postcode_modal" closedby="none">
<h2>Vul je postcode en huisnummer in.</h2> <h2>Vul je postcode en huisnummer in.</h2>
<form id="postcode_modal_form" method="post" action="" novalidation> <p>Onze prijzen zijn afhankelijk van de regio. Vul daarom de postcode en het huisnummer in om de exacte prijzen te bekijken.</p>
<form id="postcode_modal_form" method="post" action="" novalidate>
<div class="form_fields"> <div class="form_fields">
<div> <div>
<input type="text" name="postcode" <!-- Dutch Postcode Field -->
<input
type="text"
name="postcode"
title="Voer een geldige Nederlandse postcode in (bijv. 1234AB of 1234 AB)." title="Voer een geldige Nederlandse postcode in (bijv. 1234AB of 1234 AB)."
pattern="[1-9][0-9]{3} ?(?!sa|sd|ss)[a-zA-Z]{2}" pattern="[1-9][0-9]{3} ?(?!sa|sd|ss)[a-zA-Z]{2}"
placeholder= "1010 AA" placeholder="1010 AA"
size="10" size="10"
required required
autocomplete="off"
/> />
<input type="text" name="huisnummer" <!-- House Number Field -->
pattern="/\d+([-\\s]?[a-zA-Z]+)?/" <input
type="text"
name="huisnummer"
title="Voer een geldig huisnummer in (bijv. 1, 1A, 1-A, 1a)." title="Voer een geldig huisnummer in (bijv. 1, 1A, 1-A, 1a)."
placeholder= "12A" pattern="\d+([- ]?[a-zA-Z]+)?"
placeholder="10"
size="5" size="5"
required required
autocomplete="off"
/> />
</div> </div>
<button id="postcode_modal_submit" type="submit">verzend</button> <button id="postcode_modal_submit" type="submit">OK</button>
</div> </div>
</form> </form>
<div class="error_message_modal_postcode" id="error_message_modal_postcode" aria-live="polite"></div> <div class="error_message_modal_postcode" id="error_message_modal_postcode" aria-live="polite"></div>
<div class="loader_modal"></div>
</dialog> </dialog>
<?php <?php
} }
@@ -182,21 +190,13 @@ function handle_postcode_modal($data)
$_SESSION["straatnaam"] = $result["straatnaam"]; $_SESSION["straatnaam"] = $result["straatnaam"];
$_SESSION["woonplaats"] = $result["woonplaats"]; $_SESSION["woonplaats"] = $result["woonplaats"];
$_SESSION["postcode_is_local"] = postcode_in_range( $_SESSION["postcode_is_local"] = postcode_in_range($params["postcode"]);
$params["postcode"],
5000,
5800,
);
$resp = [ $resp = [
"status" => "success", "status" => "success",
"message" => "all good", "message" => "all good",
"straatnaam" => $result["straatnaam"], "straatnaam" => $result["straatnaam"],
"lokaal_trarief" => postcode_in_range( "lokaal_trarief" => postcode_in_range($params["postcode"]),
$params["postcode"],
5000,
5800,
),
]; ];
} else { } else {
$resp = [ $resp = [
@@ -270,7 +270,7 @@ function getStraatnaam($postcode, $huisnummer)
]; ];
} }
function postcode_in_range($postcode, $start, $end) function postcode_in_range($postcode)
{ {
$cleanPostcode = strtoupper(preg_replace("/\s+/", "", $postcode)); $cleanPostcode = strtoupper(preg_replace("/\s+/", "", $postcode));
@@ -280,7 +280,10 @@ function postcode_in_range($postcode, $start, $end)
$numberPart = (int) substr($cleanPostcode, 0, 4); $numberPart = (int) substr($cleanPostcode, 0, 4);
return $numberPart >= $start && $numberPart <= $end; return ($numberPart >= 4800 && $numberPart <= 4899) ||
($numberPart >= 5000 && $numberPart <= 5199) ||
($numberPart >= 5260 && $numberPart <= 5268) ||
($numberPart >= 5688 && $numberPart <= 5689);
} }
function modify_checkout_with_js() function modify_checkout_with_js()