Tagged: jQuery, php, woocommerce, wordpress
-
AuthorPosts
-
April 4, 2019 at 10:32 am #1086955
Hi,
In the builder I am using the product grid and load in the main category ‘Alpincenter Bottrop’.
So in the front-end I am getting code like this:<ul class="products"> <li class="post-3204 product type-product status-publish product_cat-alpincenter-bottrop product_cat-winter-all-incl-dagticket-ma-t-m-vrij first instock sale shipping-taxable purchasable product-type-simple"></li> <li class="post-3206 product type-product status-publish product_cat-winter-all-incl-dagticket-ma-t-m-do product_cat-alpincenter-bottrop last instock sale shipping-taxable purchasable product-type-simple"></li> <li class="post-3211 product type-product status-publish product_cat-alpincenter-bottrop product_cat-winter-all-incl-dagticket-zat-zon last instock sale shipping-taxable purchasable product-type-simple"></li> <li class="post-3213 product type-product status-publish product_cat-alpincenter-bottrop product_cat-winter-all-incl-dagticket-zat-zon last instock sale shipping-taxable purchasable product-type-simple"></li> </ul>
What I want is to
.wrapAll()
the<li>
items which have the same categories both.
So if they have bothproduct_cat-alpincenter-bottrop
andproduct_cat-winter-all-incl-dagticket-zat-zon
for example this<li>
items needs to be wrapped in a DIV called<new />
.So the products with same subcategory will be nested with each other ;)
Also I want to echo the category names of the products in the DIV
<new />
In the private content there is a link to the product like how it is now.
April 7, 2019 at 4:16 am #1087875Hey (Email address hidden if logged out) ,
Sorry for the late reply, but it looks like you have already found the solution for this, I was going to suggest to try adding this code to the end of your functions.php file in Appearance > Editor:function custom_script(){ ?> <script> (function($){ $(document).ready(function(){ $('li.product_cat-alpincenter-bottrop.product_cat-winter-all-incl-dagticket-zat-zon').wrapAll('<div class="new" />') }); })(jQuery); </script> <?php } add_action('wp_footer', 'custom_script');
Best regards,
MikeApril 8, 2019 at 9:40 am #1088199Hi Mike,
It needs to auto detect which elements has the same category.
So when the customer adds a category I don’t have so edit the code again.April 9, 2019 at 4:09 am #1088514 -
AuthorPosts
- You must be logged in to reply to this topic.