Buy me a coffee

Assign Additional Info based on Category

Suppose you have 6 products: A, B, C, D, E, F, and 3 product categories: Bike, Car, Plane. You want products in each category to use the same additional information.

Instead of manually entering the description into Additional Info, you want to add it automatically to products in these 3 categories, each with a different description.

Assign Additional Info Based On Category 01 Min

#1. You create 3 tags: Bike, Car, and Plane, and assign them to corresponding products. (We have to create tags because we cannot target categories with code.)

Assign Additional Info Based On Category 03 Min

Assign Additional Info Based On Category 02 Min

Assign Additional Info Based On Category 04 Min

#2. Create 3 Pages in Not Linked with Name/URL

  • Bike – /bike
  • Car – /car
  • Plane – /plane

Assign Additional Info Based On Category 05 Min

Assign Additional Info Based On Category 06 Min

Assign Additional Info Based On Category 07 Min

Assign Additional Info Based On Category 08 Min

#3. Add Text to these pages, here I used a random text.

Assign Additional Info Based On Category 10 Min

Assign Additional Info Based On Category 09 Min

Assign Additional Info Based On Category 11 Min

#4. Install this Plugin

The plugin will give you some code to add to the Code Injection Header and footer, like this.

Add A Section To Top Of Blog Posts Use Not Linked Page 03 Min

Add A Section To Top Of Blog Posts Use Not Linked Page 04 Min

#5. Use this code to Code Injection – Footer or Shop/Store Page Header Code Injection

<div data-wm-plugin="load" data-target="/bike"></div>
<div data-wm-plugin="load" data-target="/car"></div>
<div data-wm-plugin="load" data-target="/plane"></div>

Assign Additional Info Based On Category 12 Min

#6. Use this code to Code Injection – Footer or Shop/Store Page Header Code Injection, under #5 code.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
document.addEventListener('wmSectionLoader:loaded', ({detail}) => {
  if (detail.target !== '/bike') return;
  $('[data-target="/bike"]').insertBefore('section.ProductItem-additional');
})
</script>
<script>
document.addEventListener('wmSectionLoader:loaded', ({detail}) => {
  $('.wm-load-container').insertBefore('section.ProductItem-additional');
})
</script>

Assign Additional Info Based On Category 13 Min

#7. Use this code to Custom CSS box

/* CSS */
.tag-bike [data-target="/bike"] {
    display: block !important;
}
.tag-car [data-target="/car"] {
    display: block !important;
}
.tag-plane [data-target="/plane"] {
    display: block !important;
}

Assign Additional Info Based On Category 14 Min

#8. Result

Assign Additional Info Based On Category 17 Min

 

Assign Additional Info Based On Category 16 Min

 

Assign Additional Info Based On Category 15 Min