Dynamically add WooCommerce Products to Category based on Atrributes

Job ID: 33893687

Budget: £10 – £20 GBP

We are looking for a piece of code to go into functions.php in WooCommerce which will allow us to add a product to a certain category if one of the attributes has the same value as the category name.

We sell items where the customer can choose from different breeds of dog to be printed onto varying items. We use a plugin which automatically creates all of these variations as single products in the catalogue, however as this is based off of the variation, this means we need to select every breed of dog as a category choice for it to be displayed in the catalogue.

The issue this creates is that if a customer chooses the category 'Greyhound' for example, they will see every variation of other breeds which ruins the category.

What we are after is, for example, if attribute pa_breed = 'Greyhound' then display this product in the category 'Greyhound'.

We hope this makes sense and look forward to working with you - many thanks for your time!
Related categories: PHP AJAX WordPress WooCommerce