Implementing HubBox on WooCommerce

This guide explains how to integrate HubBox pickup point selection into your WooCommerce store using the HubBox Tag script. This method involves adding HubBox's JavaScript directly into your website's frontend on the checkout page.

For full details on the HubBox Tag, refer to the Tag documentation.

Tag documentation

Prerequisites

Requirement Details
WooCommerce store A functioning WooCommerce installation on WordPress
Admin access WordPress admin privileges to install plugins or edit theme files
HubBox Tag script The JavaScript snippet or CDN URL provided by your HubBox Integrations Manager — unique to your account

Choosing an Implementation Method

There are two primary ways to add the HubBox Tag script to your WooCommerce site. Choose the method that best suits your setup before proceeding.

Method A: Code Snippet Plugin (Recommended)

A plugin provides a user-friendly interface within WP Admin, reduces the risk of PHP errors breaking your site, and typically includes options to load scripts only on specific pages such as the checkout.

The trade-off is an additional plugin dependency.

Method B: functions.php (Child Theme or Custom Plugin)

Editing functions.php requires no extra plugin and gives direct control via code. However, it requires familiarity with PHP and WordPress hooks.

Never edit your main theme's functions.php directly — changes will be lost on theme updates and PHP errors can break your site. Always use a Child Theme or a site-specific custom plugin.


Method A: Implementation via Plugin

Obtain Your HubBox Tag Script

Before you begin, ensure you have the correct HubBox Tag script from your HubBox Integrations Manager. This JavaScript snippet contains your unique configuration ID and the logic required to display and manage the HubBox pickup point selection interface on your WooCom checkout.

You can access the Tag script via Console by going to "Setup" and then "Tag Management" in the menu.

Install a Code Snippet Plugin

Install a reputable plugin designed for adding custom code snippets or header/footer scripts. Options include:

HubBox is not affiliated with these third-party plugins. Evaluate them based on your needs, compatibility, and reviews before installing.

Create a New Snippet

Navigate to the plugin's interface within your WP Admin panel and create a new snippet. Configure it as follows:

!cdn.hub-box.com/console/woocom/woocom-snippet-plugin.png

Save the Snippet

Save the snippet and confirm it is active. Refer to your chosen plugin's documentation for any plugin-specific steps.


Method B: Implementation via functions.php

Only use this method if you are comfortable editing PHP and are working within a Child Theme or custom plugin. Incorrect PHP code can break your site.

Obtain Your HubBox Tag Script

Ensure you have the correct HubBox Tag script or CDN URL from your HubBox Integrations Manager before proceeding.

Access functions.php

Open the functions.php file of your active Child Theme (or your custom plugin file) using one of the following methods:

Add the PHP Code

Paste the appropriate code snippet at the end of the file. Choose the method that matches what HubBox provided.

Recommended: Enqueueing the Script (CDN URL)

This method correctly adds the script to the WordPress page load queue and supports footer loading. Replace YOUR_HUBBOX_CDN_SCRIPT_URL_HERE with the URL provided by HubBox.

/**
 * Enqueue HubBox Tag Script on WooCommerce Checkout Page.
 */
function enqueue_hubbox_checkout_script() {
    if ( function_exists( 'is_checkout' ) && is_checkout() ) {
        wp_enqueue_script(
            'hubbox-tag',                        // Unique handle for the script
            'YOUR_HUBBOX_CDN_SCRIPT_URL_HERE',   // CDN URL provided by HubBox
            array(),                             // Dependencies (usually empty)
            null,                                // Script version (optional)
            true                                 // Load in footer (recommended)
        );
    }
}
add_action( 'wp_enqueue_scripts', 'enqueue_hubbox_checkout_script' );

Alternative: Embedding a Full Script Block (wp_footer)

If HubBox provided a full <script>...</script> block rather than a CDN URL, use this method instead. Replace the comment block with the complete script provided by HubBox.

/**
 * Add HubBox Tag Script Block to Footer on WooCommerce Checkout Page.
 */
function add_hubbox_footer_script() {
    if ( function_exists( 'is_checkout' ) && is_checkout() ) {
        ?>
        <script>
        // PASTE FULL HUBBOX TAG SCRIPT BLOCK HERE
        // (including the config object inside)
        </script>
        <?php
    }
}
add_action( 'wp_footer', 'add_hubbox_footer_script' );

Save Changes

Save the functions.php file. If the page breaks after saving, check for PHP syntax errors in the code you added.


Testing the Implementation

Enable Test Mode

Locate the config object within the HubBox Tag script and set the mode property to "test":

config: {
    mode: "test", // Set to "test" for testing
    // ... other configuration options ...
}

Activate the Test View

With mode: "test" set, the HubBox widget only appears when a specific query parameter is appended to your checkout URL. Navigate to your WooCommerce checkout page and add ?hubboxPayloadTest=true to the end of the URL:

yourstore.com/checkout/?hubboxPayloadTest=true

This allows you to see and interact with the HubBox integration without affecting regular customers.

If you have a WordPress staging environment, test there first before testing on your live site.

Verify the Integration

Work through the following checklist during testing:


Going Live

Once testing is complete and you are satisfied with the integration:

Update the Mode

Access the HubBox Tag script via your plugin or child theme's functions.php and change the mode property from "test" to "live":

config: {
    mode: "live", // Set to "live" for deployment
    // ... other configuration options ...
}

Save Changes

Save the script. HubBox pickup options will now be live for all eligible customers.


Advanced Configuration

The HubBox Tag script includes a config object where advanced features such as product eligibility filtering and shipping rate filtering can be configured.

Product Eligibility Filtering (getShouldBailOut)

Use this feature to prevent the HubBox pickup option from appearing when the cart contains items unsuitable for pickup (e.g., oversized or hazardous items). This is configured using the callbacks.getShouldBailOut function within the Tag script's config.

The function must return true to hide HubBox ("bail out") or false to show it. For guidance on eligibility strategy, refer to the /docs/product-eligibility.

The examples below should be added within config.callbacks in your HubBox Tag script.

Example 1: Hide pickup based on specific SKUs

This example checks the cart against a predefined list of ineligible SKUs. It relies on product data being available in a window.dataLayer_content object, which is common in Google Tag Manager / GA4 setups for WooCommerce. Verify your data layer structure before using this approach.

callbacks: {
    getShouldBailOut: () =>
        new Promise((resolve) => {
            try {
                const notAllowed = ["SKU-NO-PICKUP-1", "SKU-NO-PICKUP-2"]; // Your ineligible SKUs
                const products = window?.dataLayer_content?.ecommerce?.checkout?.products;
                if (!Array.isArray(products)) {
                    console.warn("HubBox Bailout: Data layer for products not found or not an array.");
                    resolve(false);
                    return;
                }
                const cartSkuList = products.map((product) => product?.sku);
                const hasNotAllowedSku = cartSkuList.some((sku) => notAllowed.includes(sku));
                resolve(hasNotAllowedSku); // Bail out (true) if an ineligible SKU is found
            } catch (error) {
                console.error("HubBox Bailout SKU Check Error:", error);
                resolve(false); // Default to not bailing out on error
            }
        }),
}
Example 2: Hide pickup based on cart total value

This example reads the cart total from the DOM and bails out if it meets or exceeds a defined threshold.

This approach relies on scraping a value from the DOM and is sensitive to theme and plugin changes. The CSS selector below targets a standard WooCommerce order review table — you may need to adjust it for your theme. A server-side check or WooCommerce session data via AJAX is more robust if available.

callbacks: {
    getShouldBailOut: () => new Promise(resolve => {
        try {
            // Adjust this selector to match your theme's order total element
            var selector = ".shop_table.woocommerce-checkout-review-order-table .order-total .woocommerce-Price-amount.amount";
            var totalElement = document.querySelector(selector);
            if (!totalElement) {
                console.warn("HubBox Bailout: Cart total element not found with selector:", selector);
                resolve(false);
                return;
            }
            // Parse the total value — adjust for your store's currency format
            var total = Number(
                totalElement.innerText
                    .replace(/[^0-9.,]+/g, "")
                    .replace(",", ".")
            );
            const maxPickupValue = 5000; // Set your threshold
            resolve(total >= maxPickupValue); // Bail out if total meets or exceeds threshold
        } catch (error) {
            console.error("HubBox Bailout Value Check Error:", error);
            resolve(false); // Default to not bailing out on error
        }
    }),
}

Shipping Rate Filtering

Use this feature to show or hide specific WooCommerce shipping methods based on whether the customer selects Home Delivery or HubBox Pickup. This is configured within the config.shippingMethods object in your HubBox Tag script. For strategy guidance, refer to the /docs/shipping-rate-filtering.

config: {
    shippingMethods: {
        wrapper: '#shipping_method',
        interactionPreventionAction: 'hide li',
        excludeOnLocalPickup: [
            {
                selectors: [
                    'text-fragment: Royal Mail',
                    'text-fragment: Evri',
                ],
            },
        ],
    },
}

Expected Outcome

Once the HubBox Tag script is correctly implemented and live:


Troubleshooting

The HubBox UI is not appearing on the checkout page
  1. Confirm the snippet is active and scoped to the checkout page only (not site-wide).
  2. If using a plugin, confirm the snippet is enabled and saved correctly.
  3. If using functions.php, confirm the file was saved without PHP errors and the child theme is active.
  4. If testing, confirm you have appended ?hubboxPayloadTest=true to the checkout URL and that mode is set to "test" in the script config.
  5. Open the browser developer console (F12) and check for JavaScript errors referencing HubBox.
The shipping address is not updating after a pickup point is selected
  1. Confirm the HubBox Tag script is complete and unmodified.
  2. Verify the configId within the script is correct for your environment.
  3. Check the browser Network tab for failed requests (look for nearest or within in request URLs).
  4. Check the browser console for JavaScript errors at the point of selection.
The `getShouldBailOut` callback is not behaving as expected
  1. Add console.log statements within your callback to trace the execution path and confirm the expected data is available.
  2. If using the SKU example, confirm the window.dataLayer_content object exists and contains the expected structure on your checkout page.
  3. If using the cart total example, confirm the CSS selector matches the actual DOM element on your checkout page using browser developer tools.
  4. Check the browser console for errors thrown within the callback — unhandled errors will cause the .catch() block to resolve false (not bail out).
Shipping rate filtering is not hiding or showing the correct methods
  1. Inspect the checkout page DOM using browser developer tools to confirm the wrapper selector (#shipping_method) matches the actual element on your checkout page — this may differ depending on your theme or checkout plugins.
  2. Confirm the text-fragment values in excludeOnLocalPickup match the exact text displayed for each shipping method on your checkout.
  3. Test with a single exclusion rule first to isolate the issue before adding multiple rules.
HubBox conflicts with my theme or other checkout plugins
  1. Temporarily deactivate other checkout-related plugins one at a time to identify the source of the conflict.
  2. Check the browser console for JavaScript errors that may indicate a script loading order issue.
  3. If using the CDN method, ensure the HubBox config is defined before the script loads (see the test mode section above for guidance on inline config with CDN scripts).
  4. Contact HubBox support with details of the conflicting plugin or theme if the issue persists.