How do I set up custom product categories?

How do I set up custom product categories?

antondev
Visitor
1 0 0

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!

Reply 1 (1)

PageFly-Amelia
Shopify Partner
576 162 232

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.