Ik heb de volgende code voor een zoek balk op mijn frontpage van mijn wordpress website.
Het laat de categorieën van woocommerce zien.
De "var search_url" verwijst naar de categorie pagina. dit gaat goed alleen niet met de juist query of url.
Ik krijg dit /product-category/andorra/?product_subcat=grandvalira&product_subsubcat=el-tarter en het moet zijn /product-category/andorra/grandvalira/el-tarter/.
Heeft iemand een idee wat het probleem kan zijn? ik kom er niet meer uit.
Code:// Define shortcode for the search barfunction custom_search_bar_shortcode() { ob_start(); ?> <form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '//' ) ); ?>"> <?php // Get top-level product categories $product_categories = get_terms( array( 'taxonomy' => 'product_cat', 'hide_empty' => true, 'parent' => 0, ) ); if ( $product_categories ) : ?> <select name="product_cat" id="product_cat"> <option value=""><?php esc_html_e( 'Landen', 'text-domain' ); ?></option> <?php foreach ( $product_categories as $category ) : ?> <option value="<?php echo esc_attr( $category->slug ); ?>"><?php echo esc_html( $category->name ); ?></option> <?php endforeach; ?> </select> <select name="product_subcat" id="product_subcat" style="display: show;"> <option value=""><?php esc_html_e( 'Skigebieden', 'text-domain' ); ?></option> </select> <select name="product_subsubcat" id="product_subsubcat" style="display: show;"> <option value=""><?php esc_html_e( 'Bestemmingen', 'text-domain' ); ?></option> </select> <button type="submit" class="button_front_search"><i class="fas fa-search"></i><?php esc_html_e( '', 'text-domain' ); ?></button> <?php endif; ?> </form> <script> jQuery(document).ready(function($) { $('#product_cat').change(function(){ var category = $(this).val(); if(category){ $.ajax({ url: '<?php echo admin_url('admin-ajax.php'); ?>', type: 'POST', data: 'action=get_subcategories&category='+category, success:function(data){ $('#product_subcat').html(data); $('#product_subcat').show(); } }); } else { $('#product_subcat').html('<option value=""><?php esc_html_e( 'Select Subcategory', 'text-domain' ); ?></option>'); $('#product_subsubcat').html('<option value=""><?php esc_html_e( 'Select Subsubcategory', 'text-domain' ); ?></option>'); $('#product_subcat').show(); $('#product_subsubcat').show(); } }); $('#product_subcat').change(function(){ var subcategory = $(this).val(); if(subcategory){ $.ajax({ url: '<?php echo admin_url('admin-ajax.php'); ?>', type: 'POST', data: 'action=get_subsubcategories&subcategory='+subcategory, success:function(data){ $('#product_subsubcat').html(data); $('#product_subsubcat').show(); } }); } else { $('#product_subsubcat').html('<option value=""><?php esc_html_e( 'Select Subsubcategory', 'text-domain' ); ?></option>'); $('#product_subsubcat').show(); } }); // Update form action URL based on the selected subsubcategory $('#product_subsubcat').change(function(){ var subsubcategory = $(this).val(); if(subsubcategory){ var product_cat = $('#product_cat').val(); var product_subcat = $('#product_subcat').val(); var search_url = 'product-category/' + product_cat + '/' + product_subcat + '/' + subsubcategory + '/'; $('.woocommerce-product-search').attr('action', search_url); } }); }); </script> <?php $output = ob_get_clean(); return $output; } add_shortcode( 'custom_search_bar', 'custom_search_bar_shortcode' ); // AJAX function to get subcategories add_action('wp_ajax_get_subcategories', 'get_subcategories_callback'); add_action('wp_ajax_nopriv_get_subcategories', 'get_subcategories_callback'); function get_subcategories_callback() { $category = $_POST['category']; $subcategories = get_terms( array( 'taxonomy' => 'product_cat', 'hide_empty' => true, 'parent' => get_term_by('slug', $category, 'product_cat')->term_id, ) ); if ( $subcategories ) { $output = '<option value="">' . esc_html__( 'Kies Skigebied', 'text-domain' ) . '</option>'; foreach ( $subcategories as $subcategory ) { $output .= '<option value="' . esc_attr( $subcategory->slug ) . '">' . esc_html( $subcategory->name ) . '</option>'; } echo $output; } wp_die(); } // AJAX function to get subsubcategories add_action('wp_ajax_get_subsubcategories', 'get_subsubcategories_callback'); add_action('wp_ajax_nopriv_get_subsubcategories', 'get_subsubcategories_callback'); function get_subsubcategories_callback() { $subcategory = $_POST['subcategory']; $subsubcategories = get_terms( array( 'taxonomy' => 'product_cat', 'hide_empty' => true, 'parent' => get_term_by('slug', $subcategory, 'product_cat')->term_id, ) ); if ( $subsubcategories ) { $output = '<option value="">' . esc_html__( 'Kies Bestemming', 'text-domain' ) . '</option>'; foreach ( $subsubcategories as $subsubcategory ) { $output .= '<option value="' . esc_attr( $subsubcategory->slug ) . '">' . esc_html( $subsubcategory->name ) . '</option>'; } echo $output; } wp_die(); }
- zoek balk niet de juiste query of url
-
08-05-2024, 21:41 #1
- Berichten
- 3
- Lid sinds
- 1 jaar
zoek balk niet de juiste query of url
-
In de schijnwerper
Logo nodig? Nu 75,- ( ook andere grafische opdrachten )Freelance / WerkBlogplaatsing Lifestyle website 50.000 bezoekers p/m (DR 44, DA 35, PA 43)LinkpartnersSnatcher.nl - Slechts €10 - Snatch Quarantaine DomeinnamenPromotieHulc is vernieuwd! Grootste outreach platform van de BeneluxLinkpartners -
11-05-2024, 14:51 #2
- Berichten
- 3
- Lid sinds
- 1 jaar
Re: zoek balk niet de juiste query of url
Opgelost!
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic