WOOT - WooCommerce Active Products Tables

WooCommerce product table enquiry button with a prefilled form

A WooCommerce product table enquiry button puts "Ask about this product" into every row and opens a contact form that already knows which product the visitor means. Quote-only catalogs, B2B shops and products without a public price need it most: WooCommerce does not consider a product without a price purchasable, so the table's Cart column stays empty for it. The table has no ready enquiry column, but one short snippet adds it. Below is how to build the column, prefill Contact Form 7 or WPForms with the product, open the form in a popup over the table, and what to expect from request-a-quote plugins.

How a button column works in the products table

Every column of the table is a field with an action callback that receives the product ID and returns the cell's HTML. The woot_profile_extend hook adds your own field, and it then appears in the Field list of the Columns tab like any built-in one. The custom button FAQ shows the principle; this page goes further. Three facts about how the table loads shape everything that follows:

  • The rows are built on the server in a separate AJAX request to /wp-admin/admin-ajax.php, after the page itself has loaded.
  • Scripts that look for their buttons once, when the page loads, never see buttons inside the rows.
  • Scripts placed inside a cell are not executed, because the browser does not run scripts inserted that way.

So the button has to carry everything it needs in its own markup: a link with the product in its address.

Step 1: a form page that reads the product from the link

Create a page, for example /product-enquiry/, and put your form on it. The table will open it with the product in the query string, and the form fills its fields from there.

Contact Form 7

Contact Form 7 reads a field's default value from the URL with the default:get option: the field named product takes the value of ?product=…. In the form template:

<label> Your name [text* your-name] </label>
<label> Your email [email* your-email] </label>
<label> Product [text product readonly default:get] </label>
[hidden product-url default:get]
[hidden table-page default:get]
<label> Your question [textarea your-message] </label>
[submit "Send enquiry"]

In the Mail tab, add [product], [product-url] and [table-page] to the message body so the email names the product, links to it and shows the page where the visitor found it (table-page is filled by the popup version in step 3).

Prefer this to filling fields with JavaScript. A value set by a script can appear for a moment and vanish, because some form scripts reset the form after it loads, and a reset returns every field to the default the server printed. A default:get value is that server default, so it survives.

WPForms

Turn on dynamic field population in the form's advanced settings. The form then accepts values in parameters named wpf + form ID + _ + field ID: ?wpf641_4=Blue+Shirt fills field 4 of form 641. Use these names instead of product and product-url in the snippet below. Other form plugins have similar options, usually called dynamic or URL prefill.

Step 2: add the enquiry button column to the WooCommerce product table

/*
 * Products tables: an "Enquiry" column with a link to the form page.
 * Child theme functions.php or a code snippets plugin.
 */
add_filter('woot_profile_extend', function ($profile, $action) {

    if ('woot_woocommerce_tables' !== $action) {
        return $profile;
    }

    $profile['enquiry'] = [
        'title'  => 'Enquiry',
        'order'  => false, // not sortable
        'action' => function ($post_id) {
            $product = wc_get_product($post_id);
            if (!$product) {
                return '';
            }

            $name = wp_strip_all_tags($product->get_name());
            if ($product->get_sku()) {
                $name .= ' (SKU ' . $product->get_sku() . ')';
            }

            // Parameter names = form field names; values must be encoded
            $url = add_query_arg([
                'product'     => rawurlencode($name),
                'product-url' => rawurlencode(get_permalink($post_id)),
            ], home_url('/product-enquiry/'));

            return WOOT_HELPER::draw_html_item('a', [
                'href'  => esc_url($url),
                'class' => 'woot-btn',
            ], WOOT_Vocabulary::get('Ask about this product'));
        },
    ];

    return $profile;
}, 10, 2);

Then add the column in the Columns tab: Append column, select Enquiry in Field, switch it Active. The button uses the plugin's own woot-btn style, and WOOT_HELPER::draw_html_item() builds the tag. Because the text goes through WOOT_Vocabulary::get(), you can translate it in the Vocabulary tab. Add 'target' => '_blank' to the attributes to open the form in a new tab. To show the button only where there is no Cart button, add if ($product->is_purchasable() && $product->is_in_stock()) { return ''; } right after the product check.

Step 3: open the form in a popup over the table

On pages with tables the plugin's popup class, Popup23, is already loaded, and it can show any page in an iframe. Replace the return line of the snippet with this one:

            return WOOT_HELPER::draw_html_item('a', [
                'href'       => esc_url($url),
                'class'      => 'woot-btn',
                'data-title' => 'Ask about ' . $name,
                // add the table page address, then open the form in the popup
                'onclick'    => 'var u = new URL(this.href); u.searchParams.set("table-page", location.href); new Popup23({iframe: u.toString(), title: this.dataset.title}); return false;',
            ], WOOT_Vocabulary::get('Ask about this product'));

The onclick is part of the button itself, so it works in rows that arrive later. It also solves the question of where the enquiry came from: inside the iframe, the form only knows its own page, and Contact Form 7's [_url] mail tag would give the enquiry page. The script adds the address of the table page as table-page, which the hidden field from step 1 picks up. If scripts fail, the button still works as an ordinary link to the form page.

  • The popup shows the whole page, with the theme's header and footer. A page template without them, which many themes offer as "blank" or "canvas", keeps the popup to the form.
  • Do not put [woot_popup_iframe_button] or [woot_button] into the cell. The plugin activates those buttons once, when the page has loaded, so a copy inside a row is never activated and only jumps to the top of the page. They work fine elsewhere on the page.
  • If the popup stays blank, the form page is refusing to be framed: a security plugin or the server sends X-Frame-Options: DENY or a strict frame-ancestors rule. Allow framing by the same site (SAMEORIGIN).

Request-a-quote plugins in the table

The table's Cart column draws its own add to cart controls, so a quote plugin that replaces the add to cart button on shop pages does not change the table. Putting the quote plugin's button shortcode into a custom column through do_shortcode() often prints the shortcode as plain text. The cells are built in the admin-ajax.php request, which WordPress counts as an admin request, and many plugins register their front-end shortcodes only outside the admin. Even when the shortcode renders, its button usually depends on a script that attaches to buttons present at page load, so the click does nothing.

That leaves three working options:

  1. Use the enquiry column above for questions about one product; it needs nothing from other plugins.
  2. Make the column a "Request a quote" link to the product page (get_permalink($post_id)), where the quote plugin's button works as designed.
  3. Ask the quote plugin's developers whether its button can be printed and activated in content loaded by AJAX. That needs the shortcode registered for AJAX requests and click handling bound with event delegation, which only they can change.

Test the button and the form

  • Open the table logged out, in a private window, and click the button in several rows, including one on the second page and one in a filtered result.
  • Each time, check that the Product field shows the right name and SKU, then submit and read the email: product, product link and table page must be there.
  • Try it on a phone; switch on Mobile for the column if it should be visible there.
  • Empty fields mean a mismatch between the parameter names in the snippet and the field names in the form, or a WPForms form without dynamic population.
  • No button at all means the column is not Active in the table whose shortcode is on the page, or the snippet does not run in AJAX requests (a code snippets plugin set to front-end only).

If the button or the popup does not behave as described, post the page link and your snippet on the WOOT support forum.