First, call the wp_nav_menu function like the one below, where you want to show your menu items.
wp_nav_menu(array(
'theme_location' => 'customerservice',
'container' => false,
'walker' => new Walker_DropDown(),
'items_wrap' => '<select>%3$s</select>',
));
Then add this nav walker function to your theme functions.php
class Walker_DropDown extends Walker_Nav_Menu{
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$item_output = '';
$item->title = str_repeat("&nbsp;", $depth * 4) . $item->title;
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' value="' . esc_attr( $item->url ) .'"' : '';
$item_output .= '<option'. $attributes .'>';
$item_output .= apply_filters( 'the_title_attribute', $item->title );
$output .= $item_output;
}
function end_el(&$output, $item, $depth = 0, $args = NULL){
$output .= "</option>\n";
}
}
If you want to redirect when you select the items from the drop-down, then you need to add this jquery code on your js file like below:
$('select').change(function() { // add a container class before select like( $('.mainav select') ) to specify particular select field
window.location = $(this).val();
});
Plugins to Enhance Your WooCommerce Store
Carefully selected tools to help you customize, manage, and optimize your WooCommerce experience.
Woo Parent Category Selector
- Automatically assign parent categories when child categories are selected
- Prevent accidental removal of required parent categories
- Automatically repairs missing parent category assignments during product save
- Bulk repair existing WooCommerce product category structures
- Keeps product category structures organized and consistent
Product Catalog Mode For WooCommerce
- Turn your WooCommerce store into catalog mode instantly
- Hide Add to Cart buttons and product prices conditionally
- Apply rules by user role, country, or scheduled time periods
- Display custom messages and inquiry options for products
- Control visibility settings globally or per product
Remove Add to Cart Button for WooCommerce
- Remove Add to Cart buttons from shop and product pages
- Hide buttons conditionally for selected products or categories
- Replace Add to Cart with custom text or messages
- Control button visibility by user role and product type
- Lightweight settings interface with easy customization
Remove Product Content for WooCommerce
- Hide product title, image, price, rating, and descriptions
- Remove tabs, meta information, SKU, tags, and related products
- Control visibility separately for shop and single product pages
- Customize WooCommerce layouts without coding
- Enable or disable content elements with simple settings
Really Simple XML and HTML Sitemap
- Generate both XML and HTML sitemaps automatically
- Display sitemaps anywhere using ShortCode support
- Include pages, posts, and custom post types
- Exclude selected pages or posts easily
- Supports WPML and Polylang multilingual plugins
