1. Knowledge Base
  2. WooCommerce Product Table
  3. Advanced Usage

How to link to the product page from a custom field in the Product Table

If you need to link a custom field column to the product page, you have two options:

  1. You can manually add a link to the product page for each custom field. See this support article for details – How to format custom fields as links
  2. You can write some custom code which will add the link automatically, by filtering the content of the custom field. This option is intended for developers who are comfortable adding code to their site.

For the second option, we’ll provide some example code to get you started. Let’s assume your custom field is called event_title. Your product table will have a column for this in the columns option, e.g. [product_table columns="cf:event_title, description, categories, price, add-to-cart"]

So we need to filter the content the the cf:event_title column. To do this, add the following filter:

add_filter( 'wc_product_table_data_custom_field_event_title', function( $value, $product ) {
    // Format the custom field as a link.
    // In this example, the custom field value will be used as the text for the link.
    $value = sprintf( '<a href="%s">%s</a>', esc_url( $product->get_permalink() ), $value );

    return $value;
}, 10, 2 );

Note that the filter we use here – wc_product_table_data_custom_field_<field> – is dynamic. You will need to change the name of the filter to include the relevant custom field for your use case.

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

Related Articles