Change the Product Search Placeholder
Replaces the "Search products…" hint inside WooCommerce's product search box with your own text, such as "Search 2,000 parts by name or code".
Opens WPIDE on
Code
$wpide_search_placeholder = 'Search by name or product code'; // Placeholder text.
add_filter( 'get_product_search_form', function ( $form ) use ( $wpide_search_placeholder ) {
return preg_replace( '/placeholder="[^"]*"/', 'placeholder="' . esc_attr( $wpide_search_placeholder ) . '"', $form, 1 );
} );
Notes
Affects the classic product search widget and get_product_search_form(); the Product Search block has its own placeholder setting.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.