@rollin
To pass AJAX data to WooCommerce filter, follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
add_action('wp_ajax_filter_products', 'filter_products'); add_action('wp_ajax_nopriv_filter_products', 'filter_products'); function filter_products() { // Get the AJAX data $data = $_POST['data']; // Perform filtering logic here // Return the filtered data echo json_encode($filtered_data); // Always exit wp_die(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
jQuery(document).ready(function($) { $('#filter-button').on('click', function() { var data = { action: 'filter_products', data: $('#filter-form').serialize() }; $.post(ajaxurl, data, function(response) { // Handle the response data console.log(response); }); }); }); |