WOOT - WooCommerce Active Products Tables

Open product links in the same tab in a WooCommerce product table

In a WooCommerce product table, links open in a new tab by default: the product title, the thumbnail, category and tag links, and the Shop cart and Checkout buttons of the table cart. The idea is to keep the table page open while the shopper looks at a product, but many shops want every link to open in the same tab, or no link at all. There is no switch for the link target in the table settings. Product titles are changed with one filter; the other links need a few lines of JavaScript. Both are below, together with the options that remove links completely.

Which links open in a new tab, and what controls them

The new tab comes from the HTML attribute target="_blank". The plugin adds it in different places, so the fix depends on the link:

LinkWhere the target comes fromHow to change it
Product titleThe woot_link_target_type filter, default _blankPHP filter
ThumbnailFixed in the pluginJavaScript
Categories, tags and attributes in their columnsFixed in the pluginJavaScript, or show them as text
Shop cart and Checkout in the cart panel and cart popupFixed in the plugin's cart scriptJavaScript, or hide the buttons
The button of external (affiliate) productsFixed in the plugin's cart scriptJavaScript
Links inside a description opened with moreSet when the text is expandedJavaScript

Do not edit the plugin files to change these attributes. Every update replaces them, and the links open in a new tab again without warning. The filter and the script below live in your theme or a snippets plugin and survive updates.

Open product title links in the same tab

The title link takes its target from the woot_link_target_type filter. Return _self and titles open in the same tab in every table, the cart popup and [woot_cart] included:

/*
 * Products tables: open product title links in the same tab.
 * Child theme functions.php or a code snippets plugin.
 */
add_filter('woot_link_target_type', function ($target) {
    return '_self';
});

The new target is written into the rows when the server builds them, so reload the page with the browser cache bypassed (or clear the page cache) before testing. Variation rows in the variations popup show the title as plain text, so there is no link to change there.

Thumbnails, cart and checkout buttons: a small script

The other targets are written by the plugin's code, partly in the browser after the table or the cart has been drawn. Instead of rewriting each of them after every redraw, the script below waits for a click on a link inside a products table, a table popup or the table cart, and removes target="_blank" from that link just before the browser follows it. It works for rows loaded later by paging, sorting, filtering or load more, and for popups opened at any time.

/*
 * Products tables: open links from tables, table popups and the table cart
 * in the same tab. Add it to the footer of the site: a JavaScript snippet in
 * a code snippets plugin, or the footer scripts field of your theme.
 */
document.addEventListener('click', function (e) {
    var link = e.target.closest('a[target="_blank"]');

    if (link && link.closest('.woot-data-table, .woot-dynamic-popup-wrapper, .woot-woocommerce-cart, .woot-cart-shortcode')) {
        link.removeAttribute('target');
    }
}, true);

A few notes on this script:

  • It listens in the capture phase (the true at the end), so it runs before the click reaches the link, and the browser opens the link with the target already removed.
  • Ctrl+click, Cmd+click and the middle mouse button still open a new tab when the shopper wants one.
  • It also affects the button of external products. To keep affiliate links in a new tab, change the first selector to 'a[target="_blank"]:not(.woot-add-to-cart-btn)'.
  • If you use it, you do not need the PHP filter above, although keeping both does no harm.

If you only want to remove the cart buttons rather than change them, the Settings tab of WOOT has Hide shop cart button and Hide checkout button, which remove Shop cart and Checkout from the table cart panel and its popup.

Disable product links in the table instead

Sometimes the table is the whole shopping experience and product pages should not be reachable from it. Titles, thumbnails and terms can be shown without links. Which control applies depends on whether the table is a saved table ([woot id=...]) or a table without an ID, such as a plain [woot], the cart popup or [woot_cart].

In a saved table

  • Title: open the table, go to the Columns tab, click the edit (pencil) button of the Title column and switch on Display as text.
  • Thumbnail: in the same popup for the Thumbnail column, switch on No Link.
  • Categories, tags, attributes: each taxonomy column has its own Display as text switch.
  • Per page: the shortcode attributes post_title_as_text=1 and disable_link_on_thumb=1 do the same for one placement of the table and take priority over the column settings.

In the cart popup, [woot_cart] and tables without an ID

These tables have no column settings, so two filters control them. woot_disable_all_links_on_titles turns titles into text, and woot_disable_all_links_on_thumbs removes the thumbnail link:

/*
 * Products tables: no product links in the cart popup, [woot_cart]
 * and tables without an ID. Child theme functions.php or a code snippets plugin.
 */
add_filter('woot_disable_all_links_on_titles', '__return_true');
add_filter('woot_disable_all_links_on_thumbs', '__return_true');

The thumbnail filter also sets the default for saved tables: it applies to every table whose Thumbnail column has never had its No Link switch changed. Once that switch has been saved, on or off, the column setting wins. The title filter does not affect saved tables at all; use Display as text there. This is also the clean answer to product links in the cart popup, which the column switches do not reach: no CSS workaround with pointer-events is needed.

Check the result

  • Clear the page cache and reload the table page in a private window.
  • Right-click a title, choose Inspect and look at the link: after the PHP filter it shows target="_self".
  • Click a thumbnail, a category link, and in the cart popup Shop cart and Checkout: each should open in the same tab when the script is active.
  • If a link still opens a new tab, view the page source and check that the script is on the table page (snippet plugins can limit a snippet to some pages), then look for errors in the Console tab of the developer tools.

The [woot_cart] shortcode page describes the table cart in more detail. If a link in your table still ignores these settings, ask on the WOOT support forum and tell us which column or button it is.