1. WooCommerce Product Table
  2. Developer Documentation

Hooks and filters

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

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.

Need professional assistance?
We've partnered with Codeable to provide our customers with expert help if required.

Filters

Language filters

There are various filters provided for manipulating text strings and messages used in the plugin. Please refer to this article for filters to override the text strings.

wc_product_table_custom_class

This filter allows you to add extra CSS classes to the product table's <table> element. Any classes will be added in addition the standard classes used by the plugin. It should return a string. For example:

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

wc_product_table_row_class

This filter allows you to modify the row classes used for each row (<tr>) in the table. It expects an array of classes to be returned and takes two parameters - the classes array and the$product object for the current row.

add_filter( 'wc_product_table_row_class', function( $classes, $product ) { 
    $classes[] = 'trade';
    return $classes;
}, 10, 2 );

wc_product_table_row_attributes

Filters the row attributes used for each product row in the table. Expects an array of attributes to be returned as key => value pairs. Takes two parameters - the classes array and the $product object.

add_filter( 'wc_product_table_row_attributes', function( $atts, $product ) { 
    $atts['data-foo'] = 'bar';
    return $atts;
}, 10, 2 );

wc_product_table_header_class_<column>

This filter allows you to add additional CSS classes to the column headings (i.e. the <th> elements) in the product table. The filter name is dynamic - <column> should be replaced with the column name you wish to modify. It should return an array or classes, which are later joined together to form the CSS class.

wc_product_table_column_class_<column>

This filter allows you to add additional CSS classes to all column cells (i.e. the <td> elements) in the product table. The filter name is dynamic - <column> should be replaced with the column name you wish to modify. It should return an array or classes, which are later joined together to form the CSS class. For example:

add_filter( 'wc_product_table_column_class_price', function( $classes ) { 
    $classes[] = 'on-sale';
    return $classes;
} );

wc_product_table_column_heading_<column>

Filters the 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 precedence over the value returned from this filter.

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

wc_product_table_column_priority_<column>

Filters the column priority for all product tables. If a priority is specified within the shortcode itself (using the priorities option), then it will take precedence over the value returned from this filter.

add_filter( 'wc_product_table_column_priority_date', function( $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', function( $width ) {
    return '100px';
} );

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 (unless you're using the lazy load option, in which case only the title and content columns are searchable). To override this behavior when you're not using lazy load, 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, buy 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.

wc_product_table_minimum_search_term_length

Set the minimum search term length allowed in the main search box. Defaults to 3 characters.

add_filter( 'wc_product_table_minimum_search_term_length', function( $length ) { 
    return 5; 
} );

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 behavior 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_search_filter_get_terms_args

Filters the arguments passed to get_terms when retrieving the lists of terms (i.e. categories, tags, attribute or taxonomy terms) for the search filter dropdown menus. The filter passes an array of arguments - see get_terms for details.

wc_product_table_search_filter_terms_<filter>

Filters the list of items shown in the search filter dropdown menu for the given taxonomy. The dynamic portion of the hook is the filter name (e.g. categories, color, etc). The filter receives an array of WP_Term objects.

wc_product_table_data_filters

Modify all the dropdown search filters at once. Returns an array of arrays, with the filter's taxonomy used as the top-level array key.

 add_filter( 'wc_product_table_data_filters', function( $filters ) { 
    // Do something with the filters, e.g:
    $filters['category']['heading'] = 'Choose a category';
    return $filters;
} );

wc_product_table_data_config

Override the table configuration used when the DataTables script is initialised. You can use this filter to, for example, disable or enable specific features. The following example disables sorting in all product tables:

// Disable all column sorting
add_filter( 'wc_product_table_data_config', function( $config ) {
    $config['ordering'] = false;
    return $config;
} );

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 this format: wc_product_table_data_<column>.

For example, to override the price column you would use the filter wc_product_table_data_price. To override data for the stock column, you would use the filter wc_product_table_data_stock, etc.

Any hyphens in the column name are replaced with underscores, so for the short-description column the filter is: wc_product_table_data_short_description.

Each of these filters takes two parameters: 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', function( $name, $product ) {
    return 'Item: ' . $name;
}, 10, 2 );

wc_product_table_data_attribute_<attribute>

This filter allows you to override data for an attribute column. Replace the <attribute> portion of the filter with the relevant attribute slug. For global attributes, the attribute slug is always prefixed with pa_, e.g. pa_color. So in this case the filter would be: wc_product_table_data_attribute_pa_color.

For product-specific (or "text") attributes, you use the name defined in the Edit Product screen. So for product-specific attribute size, the filter would be: wc_product_table_data_attribute_size.

The filter accepts 2 parameters – the current attribute value and the current product object (WC_Product).

add_filter( 'wc_product_table_data_attribute_pa_color', function( $value, $product ) { 
    return 'Color: ' . $value; 
}, 10, 2 );

wc_product_table_data_taxonomy_<taxonomy>

This filter allows you to override data for a custom taxonomy column. Replace the <taxonomy> portion of the filter with the taxonomy slug. For example, if your taxonomy is called region, the filter would be wc_product_table_data_taxonomy_region.

The filter accepts 2 parameters – the current taxonomy value and the current product object (WC_Product).

add_filter( 'wc_product_table_data_taxonomy_region', function( $value, $product ) { 
    return 'Region: ' . $value; 
}, 10, 2 );

wc_product_table_data_custom_field

Filters which allows you to override the value of any custom field displayed in the table. It accepts 3 parameters – the custom field value, the custom field name, and the current product object (WC_Product).

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

wc_product_table_data_custom_field_<field_name>

Filters which allows you to override a specific custom field in the table. Replace <field_name> in the filter with the custom field you want to filter, e.g. wc_product_table_data_custom_field_some_field.

It accepts 2 parameters – the custom field value and the current product object (WC_Product).

// Override data for the 'extra_notes' custom field.
add_filter( 'wc_product_table_data_custom_field_extra_notes', function( $value, $product ) {
    $value = 'xyz'; // example 
    return $value;
}, 10, 2 );

wc_product_table_custom_table_data_<column>

This filter allows you to add data for custom columns that you add to your product tables. Please see this article for details on adding custom columns to your table.

// Add data for a custom column 'section' which we've added to the columns option.
add_filter( 'wc_product_table_custom_table_data_section', function( $obj, $product, $args ) {
    // Create and return our custom data object.
    return new Product_Table_Section_Column( $product ); 
}, 10, 3 );

wc_product_table_acf_value

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

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

wc_product_table_custom_field_stored_date_format

If you are using date-based custom fields in your table, you may find that your dates are sometimes incorrectly sorted or formatted. The most likely cause of this is the date conversion functions used by the plugin which are built into PHP.

For example, dates such as “12/04/2018” are assumed to be in U.S. format with the month first (m/d/Y). So this example date would be December 4th, 2018.

If the date is separated by dash (-), dot (.) or other symbol, it’s assumed to be a European/Australian date with the day before the month. If you’re using dates separated by a forward slash but in this format: d/m/Y, the plugin will not be able to sort these correctly (or format them if you’re using the date_format option). To fix this, you will need to set this filter.

Note: this is not related to how the custom field is displayed in the table - see the date_format option for controlling the output of date custom fields.

add_filter( 'wc_product_table_custom_field_stored_date_format', function( $format, $field ) { 
    if ( 'despatch_date' === $field ) {
        return 'd/m/Y';
    }
    return ''; 
}, 10, 2 );

wc_product_table_custom_field_is_eu_au_date

An alternative to the above filter, you can use this shorthand filter to quickly indicate your field is stored in European/Australian format (i.e. day before month).

The filter can be applied globally to all date-based custom fields, as follows:

​add_filter( 'wc_product_table_custom_field_is_eu_au_date', '__return_true' );

Or you can use it for individual fields only, like this:

​add_filter( 'wc_product_table_custom_field_is_eu_au_date', function( $is_eu_date, $field ) {
    if ( 'event_date' === $field ) {
        return true;
    }
    return false;
}, 10, 2 );

wc_product_table_separator_<type>

Filter which allows you to change the separator used between categories, tags, terms, attributes and custom fields. For example, a product can have multiple categories, each separated by a comma. This filter allows you to change the comma for a different character, line breaks, or other custom HTML.

The filter must include the relevant type. Possible values for type are: categories, tags, terms, attributescustom_field, and custom_field_row.

For example, to change the separator between categories in the table, add this filter:

add_filter( 'wc_product_table_separator_categories', function( $sep ) {
    return '<br/>';
} );

wc_product_table_max_product_limit

This filter allows you to override the maximum product limit in the product table. This is the total number of products that can displayed in one table and defaults to 500 products. This filter will override the option set on the plugin settings page. This has no effect when using the lazy_load option as there is no limit for lazy loaded tables.

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

wc_product_table_data_cache_expiry

The length of time in seconds that the product table data will be cached. Defaults to 24 * HOUR_IN_SECONDS (1 day).

wc_product_table_use_data_cache

Filter whether to use data caching globally across all product tables. Should return true or false.

wc_product_table_query_args

Filters the query args passed to WP_Query prior to retrieving products from the database. See WP_Query documentation for details. It receives two parameters - the query args and the Table_Query object.

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

wc_product_table_meta_query

Filter the meta query used in building the product table. It receives two parameters - the meta_query array and the Table_Query object.

wc_product_table_tax_query

Filter the tax query used in building the product table. It receives two parameters - the tax_query array and the Table_Query object.

wc_product_table_user_products_query_args

Filters the query args passed to wc_get_orders prior to retrieving products from the database when displaying user products using the user_products shortcode option. See wc_get_orders and WC_Order_Query documentation for details. Takes one parameter - the query args ($order_args).

add_filter( 'wc_product_table_user_products_query_args', function( $order_args ) {
    // do something with $order_args
    return $order_args;
}, 10, 1 );

wc_product_table_optimize_table_query

Filter whether the product table query should be optimized. Defaults to true.

Optimization involves removing the content and excerpt columns from the wp_posts query to reduce the amount of data returned from the database. The optimization only occurs if the description or short-description columns are used.

add_filter( 'wc_product_table_optimize_table_query', '__return_false' );

wc_product_table_use_numeric_skus

By default, WooCommerce Product Table will use alphabetical sorting for SKUs. If you're store uses purely numerical SKUs (e.g. 256, 321, etc), you will need to enable numerical SKUs using this filter, in order for the column sorting to work correctly. Add the following code:

​add_filter( 'wc_product_table_use_numeric_skus', '__return_true' );

When using lazy load, the search box will include SKUs when searching for products. You can enable or disable this behavior by returning true or false from this filter. For example, to disable SKU searching for lazy load tables:

​add_filter( 'wc_product_table_enable_lazy_load_sku_search', '__return_false' );

wc_product_table_get_table_output

Allows you to modify the result of the Product_Table->get_table() function. Depending on the return type, the value passed to this filter could be an HTML_Data_Table object, a HTML string, and array or JSON. It takes 3 parameters: the result, the output type, and the Product_Table instance.

add_filter( 'wc_product_table_get_table_output', function( $result, $output_type, $table ) {
    // Assuming get_data() was called with 'object' return type
    if ( 'object' === $output_type ) {
        $result->add_attribute( 'data-foo', 'bar' );
    }
    return $result;
}, 10, 3 );

wc_product_table_shortcode_output

Allows you to modify the HTML returned by the [wc_product_table] shortcode. It takes 2 parameters: the HTML and the Product_Table object.

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

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', function( $class ) {
    return "btn";
} );

wc_product_table_multi_add_to_cart_data

Filters the data used for the 'Add Selected to Cart' form which adds multiple products to the cart based on the selected products. Expects an array of key => value pairs, where the key name is the name given to the hidden field input to be included in the cart data.

add_filter( 'wc_product_table_multi_add_to_cart_data', function( $data ) { 
    $data['foo'] = 'bar';
    return $data; 
} );

wc_product_table_open_products_in_new_tab

Product tables contain various links to the product details page. For example, the name and button columns 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_use_fitvids

Whether to use the FitVids library to make videos in the table responsive. Enabled by default. To disable:

add_filter( 'wc_product_table_use_fitvids', '__return_false' );

wc_product_table_enable_select2

Whether to use the Select2 library to add enhancements to the search filters and page length dropdowns above and below the table. Enabled by default. To disable:

add_filter( 'wc_product_table_enable_select2', '__return_false' );

Actions

wc_product_table_parse_args

This action is fired when the product table arguments have been parsed and set. Takes one argument - the Table_Args object for the current table.

wc_product_table_before_get_table

This action is fired once before each table is created on the page. It receives one argument - the current Product_Table object.

wc_product_table_after_get_table

This action is fired once after each table is created on the page. It receives one argument - the current Product_Table object.

wc_product_table_before_get_data

This action is fired once before the data is fetched and added to the table. It receives one argument - the current Product_Table object.

wc_product_table_after_get_data

This action is fired once after the data is added to the table. It receives one argument - the current Product_Table object.

wc_product_table_<product type>_add_to_cart

This action is fired prior to adding a product to the cart from the table. If a hook has been registered with that name, this will be run instead of the add to cart functionality built into the plugin. The hook name is dynamic and includes the product type being added - simple, variable, etc. If you want to handle the add to cart behvior yourself for a given product type, use this action.

Related Articles

Still need help?
If searching the knowledge base hasn't answered your question, please contact support.