[php]
$terms = get_terms([
‘taxonomy’ => ‘product_cat’,
‘hide_empty’ => false,
]);
echo ‘<form action=”” method=”get”><select onchange=”if(this.value) window.location.href=this.value;”><option value=””>’ . __(‘Select a category’, ‘woocommerce’) . ‘</option>’;
foreach ($terms as $term) {
$translated_id = function_exists(‘pll_get_term’) ? pll_get_term($term->term_id) : $term->term_id;
$term_link = get_term_link($translated_id, ‘product_cat’);
if (!is_wp_error($term_link)) {
echo ‘<option value=”‘ . esc_url($term_link) . ‘”>’ . esc_html($term->name) . ‘</option>’;
}
}
echo ‘</select></form>’;
[/php]