/** * Plugin Name: Marie Front * Version: 4.9 * Author: Jouw Naam */ if (!defined('ABSPATH')) exit; add_shortcode('marie_filter', function () { ob_start(); $all_attributes = wc_get_attribute_taxonomies(); $selected_attrs = get_option('marie_filter_attributes', []); $attributes = array_filter($all_attributes, function($attr) use ($selected_attrs) { return in_array('pa_' . $attr->attribute_name, $selected_attrs); }); ?>
return ob_get_clean(); }); add_action('woocommerce_product_query_tax_query', function ($tax_query, $query) { $all_attributes = wc_get_attribute_taxonomies(); $selected_attrs = get_option('marie_filter_attributes', []); $attributes = array_filter($all_attributes, function($attr) use ($selected_attrs) { return in_array('pa_' . $attr->attribute_name, $selected_attrs); }); foreach ($attributes as $attribute) { $taxonomy = 'pa_' . $attribute->attribute_name; $get_key = 'filter_' . $taxonomy; if (!empty($_GET[$get_key])) { $tax_query[] = [ 'taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => sanitize_text_field($_GET[$get_key]), ]; } } return $tax_query; }, 10, 2); add_action('woocommerce_product_query_meta_query', function ($meta_query, $query) { if (!empty($_GET['min_price'])) { $meta_query[] = [ 'key' => '_price', 'value' => floatval($_GET['min_price']), 'compare' => '>=', 'type' => 'NUMERIC', ]; } if (!empty($_GET['max_price'])) { $meta_query[] = [ 'key' => '_price', 'value' => floatval($_GET['max_price']), 'compare' => '<=', 'type' => 'NUMERIC', ]; } return $meta_query; }, 10, 2); // Voeg instellingenpagina toe add_action('admin_menu', function () { add_action('admin_menu', function () { add_options_page( 'Marie Filter Instellingen', 'Marie Filter', 'manage_options', 'marie-filter-settings', 'marie_filter_settings_page' ); }); // Registreer instellingen add_action('admin_init', function () { register_setting('marie_filter_settings_group', 'marie_filter_attributes'); }); // HTML van de instellingenpagina // HTML van de instellingenpagina met fallbackmelding $selected = get_option('marie_filter_attributes', []); ?>