1. Home
  2. Knowledge Base
  3. WooCommerce Product Table
  4. Advanced Usage
  5. Developer documentation

Developer documentation

WooCommerce Product Table comes with a number of filters which allow you to customize the plugin’s behaviour.

Please note that this code is aimed at developers and if you don’t know how to use it then you should ask your developer. If you don’t have one, we recommend posting a job on Codeable. Alternatively, please contact us to request a quote from our customizations service.

wc_product_table_supported_languages

Allows you to add additional languages into the plugin which are not currently supported. Note that you must use the correct locale for your language as the key in the $langs array. In this example we’re adding Italian so the locale is ‘it_IT’.

function wcpt_supported_languages( $langs ) {
    $langs['it_IT'] = 'http://example.com/wp-content/languages/plugins/Italian.json';
    return $langs;
}
add_filter( 'wc_product_table_supported_languages', 'wcpt_supported_languages' );

wc_product_table_language_defaults

This filter allows you to override the default values for various items of text used within the plugin. You might use this if you want to change the text for a particular item (e.g. the search box label) which has been provided by the plugin in your chosen language.

This example changes the search label to ‘Filter’, and also the empty table and zero records strings. You would need to look at the code to find the full list of strings.

function wcpt_set_language_defaults( $defaults ) {
    $defaults['search'] = 'Filter';
    $defaults['emptyTable'] = 'Sorry, no products currently available.';
    $defaults['zeroRecords'] = 'No products matched your search.';
    return $defaults;
}
add_filter( 'wc_product_table_language_defaults', 'wcpt_set_language_defaults' );

The full list of language strings and their defaults are:

Option Default Description
$defaults['info'] Showing _START_ to _END_ of _TOTAL_ products The totals message below the table.
$defaults['infoEmpty'] Showing 0 products The totals message when there are no products.
$defaults['infoFiltered'] (_MAX_ products in total) The message after the totals when searching/filtering.
$defaults[‘lengthMenu’] ‘Show _MENU_ products The text for the ‘Show X products’ dropdown.
$defaults['emptyTable'] No matching products found. Message when no products are found when table is first loaded.
$defaults['zeroRecords'] No matching products found. Message when no products are found after searching/filtering.
$defaults['search'] Search: The label for 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'] Filter: The label for the search filters.
$defaults['resetButton'] Reset The reset button text.
$defaults['multiCartButton'] Add Selected To Cart The cart button text for the multi selection.
$defaults['multiCartNoSelection'] Please select one or more products. The message when no products are selected.

wc_product_table_custom_class

Use this to add a custom CSS class to every posts table. E.g.

add_filter( 'wc_product_table_custom_class', 'wcpt_add_custom_class', 10, 2 );
function wcpt_add_custom_class( $class, $product_table ) {
    return 'my-class';
}

wc_product_table_inline_config

Filters which allows you to override the inline table configuration used when the DataTables script is initialised. You can use this filter, for example, to disable or enable certain table features. The following example disables the ordering/sorting feature in all product tables:

// Disable column sorting
add_filter( 'wc_product_table_inline_config', 'wcpt_inline_table_config', 10, 2 );
function wcpt_inline_table_config( $config, $product_table ) {
    $config['ordering'] = false;
    return $config;
}

wc_product_table_process_shortcodes

By default, WooCommerce Product Table will strip shortcodes from the main product description so any content that would appear inside these shortcodes will not appear in your table. If you wish to override this behaviour globally (for all tables), return true from this filter. If you wish to enable it for just one table, use the shortcodes option.

add_filter( 'wc_product_table_process_shortcodes', '__return_true' );

wc_product_table_data_<column>

This filter is provided to allow you to modify the column data before it is added to the table. One filter is provided for each column in the table in the format: wc_product_table_data_<column>.

For example, to override the price column you would use the filter: wc_product_table_data_price.

Any hyphens in the column name are replaced with underscores, so for the add-to-cart column the filter is: wc_product_table_data_add_to_cart.

Each of these filters takes two arguments: the data to add to the table, and the $product object (which is an instance of WC_Product).

add_filter( 'wc_product_table_data_name', 'wcpt_custom_data_name', 10, 2 );
function wcpt_custom_data_name( $name, $product ) {
    return 'Item: ' . $name;
}

wc_product_table_data_custom_field

Filters which allows you to override the value of a custom field displayed in the table. It accepts 3 arguments – the custom field value, the custom field key and the current product object.

// Override the 'extra_notes' custom field
add_filter( 'wc_product_table_data_custom_field', 'wcpt_override_custom_field', 10, 3 );
function wcpt_override_custom_field( $value, $field, $product ) {
    if ( 'extra_notes' === $field ) {
       // do something with $value
    }
    return $value;
}

wc_product_table_acf_value

Filters which allows you to override the custom field value returned from Advanced Custom Fields. It accepts 3 arguments – the custom field value, the ACF field object and the current post (i.e. product) ID.

add_filter( 'wc_product_table_acf_value', 'wcpt_override_acf_value', 10, 3 );
function wcpt_override_acf_value( $value, $field_obj, $post_id ) {
    if ( 'file' === $field_obj['type'] ) {
       // do something with $value
    }
    return $value;
}

wc_product_table_custom_data_<column>

Filter which allows you to add custom data to the table, in addition to the standard columns provided by the plugin. It accepts three arguments: the custom data to return (defaults to an empty string), the current $post object, and the current $product.

For example, to add a custom column “minimum_quantity” to your table, first add the custom column to your shortcode:
[product_table columns="title,content,date,minimum_quantity"]

Then add a filter to your theme or plugin to return this data:

add_filter( 'wc_product_table_custom_data_minimum_quantity', 'wcpt_add_custom_data_min_quantity', 10, 3 );
function wcpt_add_custom_data_min_quantity( $value, $post, $product ) {
    $value = 3; // set value as required
    return $value;
}

wc_product_table_cell_data_<column>

Filter which allows you to modify the HTML data for a cell before it is added to the table. The <column> in the filter should be replaced with the column you wish to filter. For example, the filter data in the name column:

add_filter( 'wc_product_table_cell_data_name', 'wcpt_custom_name_html', 10, 2 );
function wcpt_custom_name_html( $name, $product ) {
    return '<span class="xyz">' . $name . '</span>';
}

wc_product_table_column_heading_<column>

Filter which allows you to override a column heading for the specified column for all product tables on your site. If a custom heading is specified within the shortcode itself (in the columns option), then it will take priority over the value returned from this filter.

// Override the 'name' column heading
add_filter( 'wc_product_table_column_heading_name', 'wcpt_custom_heading_name' );
function wcpt_custom_heading_name( $heading ) {
    return 'Item Name';
}

wc_product_table_column_priority_<column>

Filter which allows you to override a column priority for all posts tables on your site. If a priority is specified within the shortcode itself (using the priorities option), then it will take priority over the value returned from this filter.

add_filter( 'wc_product_table_column_priority_date', 'wcpt_custom_priority_date' );
function wcpt_custom_priority_date( $priority ) {
    return 10; // a high number means low priority
}

wc_product_table_column_width_<column>

Filter which allows you to override a column width for all product tables on your site. If a width is specified within the shortcode itself (using the widths option), then it will take priority over the value returned from this filter.

add_filter( 'wc_product_table_column_width_sku', 'wcpt_custom_width_sku' );
function wcpt_custom_width_sku( $width ) {
    return '100px';
}

wc_product_table_max_posts_limit

Filter which allows you to override the default products limit (500 products) set by WooCommerce Product Table. Note that this option only applies when you are not using the lazy_load option.

add_filter( 'wc_product_table_max_posts_limit', 'wcpt_set_product_limit', 10, 2 );
function wcpt_set_product_limit( $limit, $product_table ) {
    return 1000;
}

wc_product_table_query_args

Filter which allows you to override the query args passed to WP_Query prior to retrieving posts from the database. See WP_Query documentation for details.

add_filter( 'wc_product_table_query_args', 'wcpt_custom_query_args', 10, 2 );
function wcpt_custom_query_args( $args, $product_table ) {
    // do something with $args
    return $args;
}

wc_product_table_shortcode_output

Allows you to modify the HTML returned by the [wc_product_table] shortcode. Takes two parameters: the HTML and the WC_Product_Table instance.

add_filter( 'wc_product_table_shortcode_output', 'wcpt_shortcode_output', 10, 2 );
function wcpt_shortcode_output( $html, $table ) {
    // do something with HTML
    return $html;
}

wc_product_table_filter_label

Allows you to change the “Filter:” label shown next to the search filters (if enabled).

add_filter( 'wc_product_table_filter_label', 'wcpt_custom_filter_label' );
function wcpt_custom_filter_label( $label ) {
    return "Search by:";
}

wc_product_table_filter_heading_<filter>

Allows you to change the heading (i.e. the default option) for the drop-down search filters shown above the table. The default heading for each filter is the same as the column heading (e.g. “Categories”, “Tags”, etc), or the custom column heading if you’ve supplied one.

You will need to append the appropriate filter name when using this hook:

  • For the categories filter: wc_product_table_filter_heading_categories
  • For the tags filter: wc_product_table_filter_heading_tags
  • For an attribute filter, e.g. pa_color: wc_product_table_filter_heading_pa_color
  • For a custom taxonomy, e.g. shop_brand: wc_product_table_heading_shop_brand

This example will change the heading for the “Categories” filter to “Filter by category”:

add_filter( 'wc_product_table_filter_heading_categories', 'wcpt_custom_categories_filter_heading' );
function wcpt_custom_categories_filter_heading( $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_label', 'wcpt_custom_reset_button' );
function wcpt_custom_reset_button( $label ) {
    return "Clear";
}

wc_product_table_multi_cart_button

Allows you to change the text used for the multiple add to cart button button above the table. Default button text is “Add Selected To Cart”.

add_filter( 'wc_product_table_multi_cart_button', 'wcpt_custom_multi_cart_button' );
function wcpt_custom_multi_cart_button( $label ) {
    return "Add Selected Products";
}

wc_product_table_multi_cart_class

Allows you to change the button class used for the multi add to cart button. Defaults to ‘button’.

add_filter( 'wc_product_table_multi_cart_class', 'wcpt_multi_cart_button_class' );
function wcpt_multi_cart_button_class( $class ) {
    return "btn";
}

wc_product_table_search_label

Allows you to modify the search label shown next to the Search box above (or below) the table. Defaults to “Search:”.

add_filter( 'wc_product_table_search_label', 'wcpt_custom_search_label' );
function wcpt_custom_search_label( $label ) {
    return "I'm Looking for:";
}

wc_product_table_open_products_in_new_tab

Product tables contain various links to the product details page. For example, the name column will (by default) include a link to the product page.

These will open in the same tab or window by default. To open them in a new tab use the wc_product_table_open_products_in_new_tab filter. For example:

add_filter( 'wc_product_table_open_products_in_new_tab', '__return_true' );

wc_product_table_column_searchable_<column>

This filter allows you to set whether or not a column is “searchable” in the product table. If a column is searchable, it means that the column will be used when the user types something into the search box above the table.

By default, the plugin includes all columns for searching, except for the image column. To override this behaviour, use this filter with the appropriate column name added to the filter.

E.g. to exclude the price column from the table search:

add_filter( 'wc_product_table_column_searchable_price', '__return_false' );

If you want to disable searching for custom fields, attributes or taxonomies, use the column name without the cf:, att: or tax: prefix:

add_filter( 'wc_product_table_column_searchable_my_custom_field', '__return_false' );

wc_product_table_column_sortable_<column>

This filter allows you to set whether or not a column is “sortable” in the product table. If a column is sortable, the table can be re-ordered by that column using the up/down arrows that appear in the column heading.

If you’re using lazy load, the sorting is restricted to certain columns only. If you’re not using lazy load, then sorting is enabled for all columns except image, add-to-cart and button.

E.g. to prevent the table being sorted by price:

add_filter( 'wc_product_table_column_sortable_price', '__return_false' );

See the note above about using this filter for custom field, attribute or taxonomy columns.

Was this article helpful?

Related Articles