From 6fd3f4a13c6b172fdcab2c8e99969f187127ef9b Mon Sep 17 00:00:00 2001 From: Remo Zaros Date: Thu, 14 May 2026 15:04:55 +0200 Subject: [PATCH] Add dropdown filter. Add label rename variable products admin --- prijs-per-postcode.php | 61 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/prijs-per-postcode.php b/prijs-per-postcode.php index 211a45d..a2ab7e7 100644 --- a/prijs-per-postcode.php +++ b/prijs-per-postcode.php @@ -26,8 +26,8 @@ class PrijsPerPostcode public function init() { $uri = $_SERVER["REQUEST_URI"]; - add_filter("woocommerce_sale_flash", "__return_null"); init_postcode_handlers($uri); + add_filter("woocommerce_sale_flash", "__return_null"); //add_action("template_redirect", [$this, "redirect_if_missing_tag"]); add_action( @@ -57,6 +57,18 @@ class PrijsPerPostcode $this, "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) @@ -155,6 +167,53 @@ class PrijsPerPostcode } 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();