使用以下代码段,希望它对您有用。我已经在我的开发机器上测试了它,它运行得很好。
/**
* Change product category dropdown placeholder text.
*
* Product category dropdown uses selectWoo/select2
* that\'s why it\'s not possible to change the placeholder text using
* woocommerce_product_categories_widget_dropdown_args filter hook.
*
* data-placeholder="" is select2 standard data api.
*
* @param string $html Dropdown html
* @param array $args Dropdown setup arguments
*
* @return string Updated $html
*/
add_filter( \'wp_dropdown_cats\', function( $html, $args ) {
if ( $args[\'taxonomy\'] === \'product_cat\' ) {
$html = str_replace( \'<select\', \'<select data-placeholder="Custom placeholder"\', $html );
}
return $html;
}, 10, 2);