onderaan het bestand
/**
* AJAX handler voor toggle bezorgmethode
*/
add_action('wp_ajax_set_delivery_method', 'set_delivery_method');
add_action('wp_ajax_nopriv_set_delivery_method', 'set_delivery_method');
function set_delivery_method() {
if (!isset($_POST['method'])) {
wp_send_json_error('Geen methode ontvangen');
}
$method = sanitize_text_field($_POST['method']);
// Zet een cookie voor 1 dag
setcookie('delivery_method', $method, time() + DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);
wp_send_json_success("Methode ingesteld op: $method");
}
/**
* Script en AJAX-variabelen insluiten
*/
add_action('wp_enqueue_scripts', function () {
wp_enqueue_script(
'delivery-toggle',
get_stylesheet_directory_uri() . '/js/script.js',
['jquery'],
null,
true
);
wp_localize_script('delivery-toggle', 'deliveryAjax', [
'ajaxurl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('delivery_nonce')
]);
});
Warning: Cannot modify header information - headers already sent by (output started at /home/pizzaeataliano/public_html/wp-content/themes/order_v1/functions.php:148) in /home/pizzaeataliano/public_html/wp-includes/pluggable.php on line 1450
Warning: Cannot modify header information - headers already sent by (output started at /home/pizzaeataliano/public_html/wp-content/themes/order_v1/functions.php:148) in /home/pizzaeataliano/public_html/wp-includes/pluggable.php on line 1453