Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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
Please let me know if it works by giving it a Like or marking it as a solution!
➜ Optimize your Shopify store with PageFly Page Builder (Free plan available)
➜ Weekly updated Shopify tutorials on YouTube
All features are available from Free plan. Live Chat Support is available 24/7.
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024