diff --git a/assets/reset-postcode.css b/assets/reset-postcode.css new file mode 100644 index 0000000..c885a29 --- /dev/null +++ b/assets/reset-postcode.css @@ -0,0 +1,22 @@ +.postcode-reset { + font-size: var(--wp--preset--font-size--small, 13px); + line-height: 1.3; + margin-top: 11px; + + a { + color: var(--wc-red); + cursor: pointer; + + &:hover { + filter: brightness(160%); + } + } + + .bevestiging { + display: none; + + &[data-open="true"] { + display: inline; + } + } +} diff --git a/assets/reset-postcode.js b/assets/reset-postcode.js new file mode 100644 index 0000000..7bb0774 --- /dev/null +++ b/assets/reset-postcode.js @@ -0,0 +1,14 @@ +document.addEventListener("click", function (event) { + event.preventDefault(); + if (event.target.matches(".reset-postcode-show-comfirm")) { + console.log("link1 button clicked!"); + document.querySelector(".bevestiging").dataset.open = true; + } + if (event.target.matches(".accept")) { + console.log("link2 button clicked!"); + } + if (event.target.matches(".decline")) { + console.log("link3 button clicked!"); + document.querySelector(".bevestiging").dataset.open = false; + } +}); diff --git a/prijs-per-postcode.php b/prijs-per-postcode.php index 0b6876d..211a45d 100644 --- a/prijs-per-postcode.php +++ b/prijs-per-postcode.php @@ -26,7 +26,8 @@ class PrijsPerPostcode public function init() { $uri = $_SERVER["REQUEST_URI"]; - if_needed_place_postcode_form($uri); + add_filter("woocommerce_sale_flash", "__return_null"); + init_postcode_handlers($uri); //add_action("template_redirect", [$this, "redirect_if_missing_tag"]); add_action( @@ -56,67 +57,6 @@ class PrijsPerPostcode $this, "controleer_postcode_op_woocommerce_paginas", ]); - add_action("wp_footer", [$this, "set_checkout_fields_with_javascript"]); - } - - public function set_checkout_fields_with_javascript() - { - if ( - !is_checkout() || - (is_wc_endpoint_url() && !is_wc_endpoint_url("order-received")) - ) { - return; - } - - $woonplaats = $_SESSION["woonplaats"]; - $postcode = $formatted_postcode = preg_replace( - "/(\d+)([A-Z]+)/", - '$1 $2', - strtoupper($_SESSION["postcode"]), - ); - $address = - $_SESSION["straatnaam"] . " " . strtoupper($_SESSION["huisnummer"]); - // Output the JavaScript - ?> - - @@ -278,3 +280,98 @@ function postcode_in_range($postcode, $start, $end) return $numberPart >= $start && $numberPart <= $end; } + +function modify_checkout_with_js() +{ + if ( + !is_checkout() || + (is_wc_endpoint_url() && !is_wc_endpoint_url("order-received")) + ) { + return; + } + + $woonplaats = $_SESSION["woonplaats"]; + $postcode = $formatted_postcode = preg_replace( + "/(\d+)([A-Z]+)/", + '$1 $2', + strtoupper($_SESSION["postcode"]), + ); + $address = + $_SESSION["straatnaam"] . " " . strtoupper($_SESSION["huisnummer"]); + // Output the JavaScript + ?> + +