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.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024