Home Forums WoodMart support forum _.template is not a function on variable product pages – triggered only by mouse

_.template is not a function on variable product pages – triggered only by mouse

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #725813

    marcosrjdesouza
    Participant

    Subject: _.template is not a function on variable product pages — triggered only by mouse interaction

    Hello,

    I’m having a JavaScript error on variable product pages that breaks the variation form rendering and causes a visible layout shift.

    Site: innovcable.com.br
    Example URL: https://innovcable.com.br/produto/cabo-de-instrumentacao-blindado-em-fita-individual-e-coletiva-bfic-300v-nbr-10300/

    The behavior

    The key detail: the error only fires when the mouse moves over the page.

    Without any mouse interaction: the page loads completely and correctly. Product code, variation swatches, and the B2BKing tiered pricing table all render. No errors in console.
    As soon as I move the mouse anywhere on the page: the error below is thrown, the variation block fails to render, and the page content shifts (Forced reflow while executing JavaScript took 36ms).

    This is reproducible on every variable product on the site.

    The error
    Uncaught TypeError: _.template is not a function
    at wp-util.min.js:2:342
    at r.onFoundVariation (add-to-cart-variation.min.js:1:6833)
    at HTMLFormElement.dispatch (jquery.min.js:2:40035)
    at v.handle (jquery.min.js:2:38006)
    at Object.trigger (jquery.min.js:2:70124)
    at HTMLFormElement.<anonymous> (jquery.min.js:2:70726)
    at ce.each (jquery.min.js:2:3129)
    at e.<computed>.each (jquery.min.js:2:1594)
    at e.<computed>.trigger (jquery.min.js:2:70701)
    at Object.success (add-to-cart-variation.min.js:1:5470)
    What I’ve already verified

    Confirmed with LiteSpeed Cache fully deactivated. I deactivated the LiteSpeed Cache plugin entirely and reloaded the page. The error occurred against the original, unmodified core files — wp-util.min.js?ver=7.0.3, add-to-cart-variation.min.js?ver=11.0.0, and jquery.min.js?ver=3.7.1 — with the standard ?ver= query strings and no minification or concatenation applied. The error was identical (wp-util.min.js:2:342), which rules out any caching or asset-optimization layer.

    Underscore is loaded and working. Running typeof _ in the console returns ‘function’, and the Network tab shows underscore.min.js loading successfully (status 200, 7.6 kB). So this is not a missing dependency — the error happens even though _ is available globally at that point.

    Tested every relevant LiteSpeed configuration before deactivating it: Combine JS disabled, Load JS Deferred disabled, Load JS Delayed never enabled, Guest Mode disabled, Minify JS tested both on and off. The error persisted in all configurations.

    Not an asset-unloading issue. I use Asset CleanUp, and it has zero unload rules for the product post type (confirmed under Bulk Changes → product). Nothing is being removed from product pages.

    Not a CSS issue. CLS measures 0.06 in Chrome DevTools. The visual jump is caused by the failed render and reflow, not by unstyled content.

    Environment
    WoodMart theme with Elementor single-product template
    Variation swatches enabled
    B2BKing (tiered pricing table on product page)
    YITH WooCommerce Product Add-ons
    WooCommerce 11.0.0, WordPress 7.0.3, jQuery 3.7.1
    Variable products using default attributes
    Why I believe this is theme-related

    The stack trace shows onFoundVariation — a WooCommerce handler — failing inside wp-util. Since Underscore is confirmed present in global scope, something appears to be affecting the scope or execution context in which that handler runs. Given that the trigger is a mouse event, I suspect the WoodMart swatch handlers (wd-swatches-variations, wd-variations-price) may be re-triggering the variation form in a context where _ isn’t resolvable.

    Could you advise whether this is a known conflict, and whether there’s a recommended configuration or patch?

    Thank you.

    #725817

    marcosrjdesouza
    Participant

    Update with additional findings

    The page loads jQuery and its dependent libraries twice — jQuery core, Migrate, blockUI, dataTables and zoom. Both loads have identical URLs from the WordPress includes folder, and both list the product page itself as the initiator.

    The page source contains only one jquery-core script tag, and the closing body tag appears only once — verified in the page source. So this is not duplicate enqueuing or template nesting; the second load happens client-side.

    This second jQuery instance appears to overwrite the global object, which would explain the _.template error: the onFoundVariation handler was registered against the first instance.

    I have already ruled out, by deactivating each and retesting: LiteSpeed Cache (fully deactivated), Asset CleanUp (no unload rules on the product post type), GTranslate, a Zoho SalesIQ widget, and the LiteSpeed crawler (which was loading other pages in the background — disabling it reduced requests from 1989 to 269, but the duplication persists).

    Could WoodMart theme scripts be re-injecting jQuery on product pages?

    #725818

    marcosrjdesouza
    Participant

    Resolved — root cause found, not theme-related

    Following up on my ticket about Uncaught TypeError: _.template is not a function on variable product pages. I found the root cause and it has nothing to do with WoodMart. Posting the details here in case it helps your team with similar reports.

    Root cause: A custom script on our site loads the Google Gen App Builder client (https://cloud.google.com/ai/gen-app-builder/client?hl=pt_BR) for an AI chat widget. That bundle ships Lodash 4.18.1 and assigns it to window._, overwriting the WordPress Underscore instance. The Lodash build in question does not include a template method.

    Since wp.template() in wp-util.min.js resolves the global _ at call time, WooCommerce’s onFoundVariation handler in add-to-cart-variation.min.js throws as soon as a variation is matched, and the variation block never renders.

    Why it looked like a mouse-triggered bug: our script attaches its loader to mouseover, scroll, touchstart and click with {once: true}, plus a 6-second fallback timer. Moving the mouse fired the load mid-render, which is why the page only broke when the pointer moved before the price appeared. Leaving the mouse still simply delayed the overwrite until after render.

    Also worth noting: I initially suspected duplicate jQuery loading and spent considerable time on LiteSpeed Cache, Asset CleanUp and theme performance settings. That turned out to be a red herring — performance.getEntriesByType(‘resource’) showed each library loading exactly once while the error still occurred.

    Fix applied: a small guard registered in the site footer that redirects any _ assignment lacking a template method to window.lodash, leaving the WordPress Underscore intact:

    js
    (function(){
    var u = window._;
    if (!u || typeof u.template !== ‘function’) return;
    Object.defineProperty(window, ‘_’, {
    configurable: true,
    get: function(){ return u; },
    set: function(nv){
    if (nv && typeof nv.template !== ‘function’) { window.lodash = nv; return; }
    u = nv;
    }
    });
    })();

    Confirmed working across multiple variable product pages, with the theme Preloader disabled.

    Thanks for your time on this one — the ticket can be closed.

    #725832

    Aizaz Imtiaz Awan
    Keymaster
    Xtemos team

    Hello,

    You are Most Welcome.

    We are glad that you managed to solve the problem yourself. You are Great!!!

    Let us know if there’s anything else we can do for you! You can always reach us at any time. We are always here to help you.

    Have a wonderful day.

    Topic Closed.
    Best Regards.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘_.template is not a function on variable product pages – triggered only by mouse’ is closed to new replies.