I'm looking for how to show products from their brand category.
My ULR is in the format www.mywebsite/brand1 or www.mywebsite/brand2 ...
My JS script with the Regex allows me to get brand1 or brand2, or whatever brand name.
I would like to display on each page the products corresponding to these brands via the product category of Woocommerce.
When I do an echo $brand
I've got exactly what I need => brand2
so I 'm thinking "that's it !"
But with my code, when I try to put the $brand into PHP it seems incorrect. Maybe my PHP variable can't be inserted like this ... I don't know ...
I've searched a lot on the web but maybe didn't google it the right way.
Any helps will be great
<script type="text/javascript">
let url = document.location.pathname;
let regex = /.*\/(.*?)\//;
let brand = url.match(regex);
// console.log(brand[1]) ---> brand2
// that's good but not enough
<?php $brand = "<script>document.write(brand[1])</script>" ?>
</script>
<?php
echo do_shortcode('[products category= "' . $brand . '" ]');
// I need to find exactly this line below
// echo do_shortcode('[products category=brand2]');
?>