Hello, Shopify Community !
Thanks for taking the time to check this out.
I’m trying to set a custom product category using JavaScript, but I’m having trouble assigning my custom categories. Specifically, I want to set the category as:
Awnings > Bear Awnings > F80 Awnings
Has anyone had experience with this or knows how to get it working? Any help would be appreciated!
Thanks in advance!
This is Amelia from PageFly - Landing Page Builder App
I think you can try adding some Javascript with the metafield or the product tags.
You can group some products with the same tag as a category.
Below is a simple code that you can set as a path for your product with category.
// Assuming you have a product object
let product = {
name: "Sample Product",
categories: []
};
// Function to set custom categories
function setCustomCategory(product, categoryPath) {
// Split the category path into an array
let categories = categoryPath.split(" > ");
// Assign the categories to the product
product.categories = categories;
}
// Example usage
setCustomCategory(product, "Awnings > Bear Awnings > F80 Awnings");
console.log(product.categories); // Output: ["Awnings", "Bear Awnings", "F80 Awnings"]
Hope that my solution works for you.
Best regards,
Amelia | PageFly