62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
|
|
session_start();
|
|
require_once "session_dialog.php";
|
|
/*
|
|
* Plugin Name: Prijs per Postcode
|
|
* Description: veschillende prijzen per postdoce. een range posctcodes zijn "lokaal" andere zijn overig
|
|
* Author: Remo Zaros
|
|
* Version: 0.0.1
|
|
* Text Domeain: prijs-per-postcode
|
|
*/
|
|
|
|
if (!defined("ABSPATH")) {
|
|
echo "big bag of potatoes";
|
|
exit();
|
|
}
|
|
|
|
class PrijsPerPostcode
|
|
{
|
|
public function __construct()
|
|
{
|
|
add_action("init", [$this, "init"]);
|
|
add_action("rest_api_init", "register_modal_api");
|
|
}
|
|
|
|
public function init()
|
|
{
|
|
$uri = $_SERVER["REQUEST_URI"];
|
|
if_needed_place_postcode_form($uri);
|
|
|
|
add_action("wp_footer", "set_checkout_fields_with_javascript");
|
|
function set_checkout_fields_with_javascript()
|
|
{
|
|
// Only run on the checkout page
|
|
if (!is_checkout() || is_wc_endpoint_url()) {
|
|
return;
|
|
}
|
|
|
|
// Define the values you want to set
|
|
$woonplaats = $SESSION["woonplaats"];
|
|
$postcode = $_SESSION["postcode"];
|
|
$address_1 =
|
|
$_SESSION["straatnaam"] . " " . $_SESSION["huisnummer"];
|
|
// Output the JavaScript
|
|
?>
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function($){
|
|
// Set the values for the checkout fields
|
|
$('#billing_city').val('<?php echo esc_js($woonplaats); ?>');
|
|
$('#billing_postcode').val('<?php echo esc_js($postcode); ?>');
|
|
$('#billing_address_1').val('<?php echo esc_js(
|
|
$address_1,
|
|
); ?>');
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
}
|
|
}
|
|
|
|
new PrijsPerPostcode();
|