SHOP BY CATEGORY
Explore Our Collections
Discover quality equipment, outdoor essentials,
home products, and much more.
(function () {
/* ====================================
CATEGORY SETTINGS
Use actual WooCommerce category IDs.
Keep ID 0 for automatic slug matching.
==================================== */
const categories = [
{
id: 0,
slug: "mowers-tractors",
name: "Mowers & Tractors",
icon: `
`
},
{
id: 0,
slug: "snow-equipment",
name: "Snow Equipment",
icon: `
`
},
{
id: 0,
slug: "trailers-hauling",
name: "Trailers & Hauling",
icon: `
`
},
{
id: 0,
slug: "sheds-outdoor-storage",
name: "Sheds & Outdoor Storage",
icon: `
`
},
{
id: 0,
slug: "auto-lifts-jacks",
name: "Auto Lifts & Jacks",
icon: `
`
},
{
id: 0,
slug: "log-splitters-wood-care",
name: "Log Splitters & Wood Care",
icon: `
`
},
{
id: 0,
slug: "pressure-washers",
name: "Pressure Washers",
icon: `
`
},
{
id: 0,
slug: "generators-power",
name: "Generators & Power",
icon: `
`
},
{
id: 0,
slug: "appliances",
name: "Appliances",
icon: `
`
},
{
id: 0,
slug: "outboard-motors-marine",
name: "Outboard Motors & Marine",
icon: `
`
},
{
id: 0,
slug: "outdoor-living-recreation",
name: "Outdoor Living & Recreation",
icon: `
`
},
{
id: 0,
slug: "home-tools-lifestyle",
name: "Home, Tools & Lifestyle",
icon: `
`
}
];
/* ====================================
WOOCOMMERCE API
==================================== */
const apiLink = document.querySelector(
'link[rel="https://api.w.org/"]'
);
const apiRoot = apiLink
? apiLink.href
: window.location.origin + "/wp-json/";
function apiURL(route, params = {}) {
const url = new URL(apiRoot);
if (url.searchParams.has("rest_route")) {
url.searchParams.set(
"rest_route",
"/wc/store/v1/" + route
);
} else {
url.pathname =
url.pathname.replace(/\/+$/, "") +
"/wc/store/v1/" + route;
}
Object.entries(params).forEach(
([key, value]) => {
url.searchParams.set(key, value);
}
);
return url.toString();
}
async function getJSON(route, params = {}) {
const response = await fetch(
apiURL(route, params),
{ credentials: "same-origin" }
);
if (!response.ok) {
throw new Error("WooCommerce API unavailable");
}
return response.json();
}
/* DECODE WOOCOMMERCE TEXT */
function decode(value) {
const el = document.createElement("textarea");
el.innerHTML = value || "";
return el.value;
}
/* ====================================
LOAD ALL PRODUCT CATEGORIES
==================================== */
async function getAllCategories() {
let list = [];
let page = 1;
while (true) {
const result = await getJSON(
"products/categories",
{
per_page: 100,
page: page,
hide_empty: false
}
);
if (!Array.isArray(result)) {
break;
}
list = list.concat(result);
if (result.length 50) break;
}
return list;
}
/* ====================================
CREATE CATEGORY CARD
==================================== */
function createCard(config, category) {
const name = decode(category.name);
const card = document.createElement("a");
card.className = "atc-card";
card.href = category.permalink ||
"/product-category/" +
encodeURIComponent(category.slug) + "/";
card.innerHTML = `
`;
card.querySelector(
".atc-name"
).textContent = name;
card.querySelector(
".atc-no-image"
).textContent = name;
/* AUTOMATIC PRODUCT COUNT */
const count = Number(category.count);
card.querySelector(
".atc-count"
).textContent = Number.isFinite(count)
? count.toLocaleString() +
(count === 1 ? " Product" : " Products")
: "Explore Products";
/* LOAD CATEGORY IMAGE */
async function loadImage() {
let imageURL = category.image?.src || "";
/* FIRST PRODUCT IMAGE FALLBACK */
if (!imageURL && category.id) {
try {
const products = await getJSON(
"products",
{
category: category.id,
per_page: 1
}
);
imageURL =
products[0]?.images?.[0]?.src || "";
} catch (error) {
imageURL = "";
}
}
if (!imageURL) return;
const photo = card.querySelector(
".atc-photo"
);
const img = document.createElement("img");
img.alt = name;
img.loading = "lazy";
img.decoding = "async";
img.addEventListener("load", function () {
const placeholder = photo.querySelector(
".atc-no-image"
);
if (placeholder) {
placeholder.remove();
}
img.style.display = "block";
});
img.addEventListener("error", function () {
img.remove();
});
img.style.display = "none";
photo.appendChild(img);
img.src = imageURL;
}
loadImage();
return card;
}
/* ====================================
INITIALIZE CATEGORY SECTION
==================================== */
async function initCategories(section) {
if (section.dataset.atcReady === "true") {
return;
}
section.dataset.atcReady = "true";
const grid = section.querySelector(
".atc-grid"
);
try {
const allCategories =
await getAllCategories();
grid.replaceChildren();
let displayed = 0;
categories.forEach(function (config) {
const category = allCategories.find(
function (item) {
if (config.id > 0) {
return Number(item.id) ===
Number(config.id);
}
return item.slug === config.slug;
}
);
/* SKIP NON-EXISTING CATEGORIES */
if (!category) return;
const card = createCard(
config,
category
);
grid.appendChild(card);
displayed++;
});
if (displayed === 0) {
const message =
document.createElement("div");
message.className = "atc-status";
message.textContent =
"Collections are currently unavailable.";
grid.appendChild(message);
}
} catch (error) {
const message =
document.createElement("div");
message.className = "atc-status";
message.textContent =
"Unable to load collections. Please refresh the page.";
grid.replaceChildren(message);
console.warn(
"AddToCart Collections:",
error.message
);
} finally {
grid.setAttribute(
"aria-busy",
"false"
);
}
}
function start() {
document.querySelectorAll(
".atc-categories"
).forEach(initCategories);
}
if (document.readyState === "loading") {
document.addEventListener(
"DOMContentLoaded",
start
);
} else {
start();
}
})();