"_local_price[" . $loop . "]", "label" => __("Lokale Prijs", "woocommerce") . " (" . get_woocommerce_currency_symbol() . ")", "value" => get_post_meta($variation->ID, "_local_price", true), "data_type" => "price", "wrapper_class" => "form-row form-row-first", // Left half ]); } public function save_local_price_field($variation_id, $i) { $local_price = $_POST["_local_price"][$i]; if (isset($local_price)) { update_post_meta( $variation_id, "_local_price", wc_clean($local_price), ); } } public function use_local_price_if_local_postcode($cart) { if (is_admin() && !defined("DOING_AJAX")) { return; } foreach ($cart->get_cart() as $cart_item) { $product = $cart_item["data"]; $variation_id = $product->is_type("variation") ? $product->get_id() : 0; if ( $variation_id && isset($_COOKIE["PPPR"]) && pppr_is_local() ) { $local_price = get_post_meta( $variation_id, "_local_price", true, ); if ($local_price) { $product->set_price($local_price); } } } } /* public function controleer_postcode_op_woocommerce_paginas() { if (is_admin() || defined('DOING_AJAX')) { return; } // 2. Define target pages (Product, Cart, Checkout, etc., but NOT the Shop home) if ( (is_product() || is_product_category() || is_product_tag() || is_cart() || is_checkout() || is_account_page()) && !is_shop() ) { // 3. Retrieve cookie safely (null coalescing prevents "Undefined index" errors) $cookie_string = $_COOKIE['PPPR'] ?? ''; // 4. Validate: Check if empty OR if the signature is invalid (tampered) // verify_ppp_cookie() returns false if the hash doesn't match the data if (empty($cookie_string) || !verify_ppp_cookie($cookie_string)) { // Optional: Clear the invalid cookie from the browser immediately setcookie('PPPR', '', time() - 3600, '/'); $shop_url = wc_get_page_permalink('shop'); // Fallback to home URL if shop page is not set if ($shop_url === -1) { $shop_url = home_url('/'); } // 5. Redirect to the shop/home page to force postcode selection wp_redirect($shop_url); exit(); } // Optional: If valid, you can now safely access the data // $is_local = ($cookie_string[0] === '1'); } } */ public function check_postcode_on_every_woocommerce_page() { if (is_admin() || defined("DOING_AJAX")) { return; } if ( (is_product() || is_product_category() || is_product_tag() || is_cart() || is_checkout() || is_account_page()) && !is_shop() ) { if (!verify_pppr_cookie_string()) { wp_redirect(home_url("/winkel/")); exit(); } } } public function display_local_price_on_product($price_html, $product) { if ( $product->is_type("variation") && isset($_COOKIE["PPPR"]) && pppr_is_local() ) { $local_price = get_post_meta( $product->get_id(), "_local_price", true, ); if ($local_price !== "") { return wc_price($local_price); } } 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; } $price = pppr_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();