1. Home
  2. Documentation
  3. WooCommerce Product Table
  4. Advanced Usage
  5. How to change the search placeholder text (Product Table)

How to change the search placeholder text (Product Table)

A ‘placeholder’ is the light-grey text shown inside a text box or form input before you start typing. They usually give some hint as to what to type in that box.

The search box shown above the product tables doesn’t have a placeholder by default. However, if you would like to use one, you can add a placeholder using the wc_product_table_language_defaults¬†filter. To do this, you will need to add the following code to your theme’s functions.php file:

function wcpt_set_language_defaults( $defaults ) {
    $defaults['searchPlaceholder'] = 'Search...'; // the search box placeholder
    return $defaults;
}
add_filter( 'wc_product_table_language_defaults', 'wcpt_set_language_defaults' );

If you also want to remove the ‘Search:’ label shown in front of the box, you can use the same filter, and set the ‘search’ property to a blank string. Amending the above code would give:

function wcpt_set_language_defaults( $defaults ) {
    $defaults['searchPlaceholder'] = 'Search...';
    $defaults['search'] = ''; // the search label
    return $defaults;
}
add_filter( 'wc_product_table_language_defaults', 'wcpt_set_language_defaults' );

Note: If you wish to translate the placeholder text into other languages then please see our article about translating WooCommerce Product Table instead.

Was this article helpful?

Related Articles