Overriding text, labels and messages in the product table
All text in WooCommerce Product Table is fully translatable in the usual way using the gettext functions provided in WordPress. A number of translations are provided in the plugin – see this article to see which languages we currently support.
Regardless of which language is used on your site, you may need to modify some of the text items used in the product tables, and we provide several hooks for this purpose. The main filter is wc_product_table_language_defaults
.
wc_product_table_language_defaults
This filter allows you to override the default values for various items of text used within the plugin.
The example below changes the search box label and the text when the table has no products:
add_filter( 'wc_product_table_language_defaults', function( $defaults ) {
$defaults['search'] = 'Filter';
$defaults['emptyTable'] = 'Sorry, no products currently available.';
return $defaults;
} );
The full list of language strings and their default values are:
Language Option | Default | Description |
---|---|---|
$defaults['info'] |
_TOTAL_ products | The totals message below the table. You can use the following placeholders: _START_, _END_ and _TOTAL_ which are replaced in the totals message. |
$defaults['infoEmpty'] |
0 products | The totals message when there are no products. |
$defaults['infoFiltered'] |
(_MAX_ in total) | The message after the totals when searching/filtering. _MAX_ is the placeholder for the number of products without search or filtering applied. |
$defaults['lengthMenu'] |
Show _MENU_ per page | The text for the page_length dropdown. _MENU_ is the placeholder for the length dropdown box. |
$defaults['emptyTable'] |
No matching products | Message when no products are found when table is first loaded. |
$defaults['zeroRecords'] |
No matching products | Message when no products are found after searching/filtering. |
$defaults['search'] |
Search: | The label shown in front of the search box. |
$defaults['searchPlaceholder'] |
The placeholder for the search box. | |
$defaults['paginate']['first'] |
First | The first pagination button. |
$defaults['paginate']['last'] |
Last | The last pagination button. |
$defaults['paginate']['next'] |
Next | The next pagination button. |
$defaults['paginate']['previous'] |
Previous | The previous pagination button. |
$defaults['filterBy'] |
The label before the search filters. | |
$defaults['thousands'] |
, | The 'thousands' separator for numbers and prices (e.g. $1,000) |
$defaults['decimal'] |
. | The decimal point for numbers and prices (e.g. $2.99) |
$defaults['resetButton'] |
Reset | The reset button text. |
$defaults['multiCartButton'] |
Add To Cart | The cart button text for multi selection (also see add_selected_button option. |
$defaults['multiCartButtonSingularPlaceholder'] |
Add 1 item for {total} | The cart button text for multi selection when 1 product is selected. You can use the following placeholders: {total}. |
$defaults['multiCartButtonPluralPlaceholder'] |
Add {items} items for {total} | The cart button text for multi selection when 2 or more products are selected. You can use the following placeholders: {items} and {total}. |
$defaults['multiCartNoSelection'] |
Please select one or more products. | The message when no products are selected. |
wc_product_table_search_label
This filter is provided for convenience, and is the same as modifying $defaults['search']
when using the wc_product_table_language_defaults
filter.
Sets the text label shown in front of the search box. Defaults to “Search:”. You can set this to an empty string (""
) to hide the label.
add_filter( 'wc_product_table_search_label', function( $label ) { return "I'm looking for:"; } );
wc_product_table_search_filter_label
This allows you to add a label in front of all of your filter dropdowns.
add_filter( 'wc_product_table_search_filter_label', function( $label ) { return "Filter by:"; } );
wc_product_table_search_filter_heading_<filter>
This filter allows you to change the heading (i.e. the default option) for the dropdown search filters. This hook name is dynamic - you will need to append the appropriate filter name to the end. For example:
- For the categories filter:
wc_product_table_search_filter_heading_categories
- For the tags filter:
wc_product_table_search_filter_heading_tags
- For an attribute whose slug is
pa_color
:wc_product_table_search_filter_heading_pa_color
- For a custom taxonomy whose slug is
brand
:wc_product_table_search_filter_heading_brand
This example will change the heading for the "Categories" filter to "Filter by category":
add_filter( 'wc_product_table_search_filter_heading_categories', function( $heading ) { return "Filter by category"; } );
wc_product_table_reset_button
Allows you to change the text used for the Reset button link above the table.
add_filter( 'wc_product_table_reset_button', function( $label ) { return "Clear"; } );
wc_product_table_multi_cart_button
Allows you to change the text for the multi-select cart button above the table, when using the Add to Cart checkboxes. The default text is “Add To Cart”. You can also set this via the plugin settings page.
add_filter( 'wc_product_table_multi_cart_button', function( $text ) {
return 'Add All Products';
} );