Change The Woocommerce Product Categories Dropdown Widget Placeholder Text

I've searched everywhere on the internet and tried to code it myself I want to change the default "Select A Category" placeholder text to "Select A Sub Category" so far I have tried this but it's not working:

function _category_dropdown_filter( $list_args ) { $list_args['show_option_none'] = __('Select A Sub Category'); return $list_args; } add_filter( 'woocommerce_product_categories_widget_arg' , '_category_dropdown_filter' );

Also, I have even tried to edit this file here but I see no "Select A Category" woocommerce/includes/widgets/class-wc-widget-product-categories.php

Topic woocommerce-offtopic dropdown widget-text widgets Wordpress

Category Web


This worked for me:

add_filter( 'wp_dropdown_cats', function( $html, $args ) {
    if ( $args['taxonomy'] === 'product_cat' ) {
        $html = str_replace( '<select', '<select data-placeholder="New Placeholder"', $html );
    }
    return $html;
}, 10, 2);

Try to using apply_filters in your functions.php

apply_filters( 'woocommerce_product_categories_widget_args','art_architecture_textbooks' );
function art_architecture_textbooks( $cat_args ) {
        $cat_args['show_option_none'] = __('Art & Architecture');
        return $cat_args;
}

Learn more https://siteorigin.com/thread/change-category-widget-default-text-select-a-category/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.