Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Add Specific Product Attribute to Title in Drop Down Display
This topic contains 7 replies, has 2 voices, and was last updated by Ernest Marcinko 7 years, 3 months ago.
- AuthorPosts
- January 7, 2017 at 10:29 pm #11492
I understand how to add a field (such as price) to the title in the drop-down display; however, I need to add a field that pulls information from the custom product attributes. The website sells mostly books – and each book has a custom attribute of “Author”. I would like to display the title and the author (if one exists) for each item in the drop down.
Ex: Mere Motherhood (Cindy Rollins)
Description goes here…If possible, I would also like it to display other specific product attributes, such as Publisher and ISBN – but only if that particular product has those attributes.
I already have the search set up so that it searches those items, but it is confusing when it finds one of those items and only displays the title and description.
Attachments:
You must be logged in to view attached files.January 10, 2017 at 4:25 pm #11532Hi!
Sorry for the late response.
Well, the plugin supports adding certain custom field values to results without any coding, but unfortunately product attributes are taxonomy terms, and it’s a bit more difficult. Since nobody had a similar request yet, I took some time to put together a small code snippet (actually two) to parse product attributes and display them within the results.
Put either of these solutions code into the functions.php file in the currently active theme directory. I hope one of them works out.
1. Solution, using the built-in woocommerce list method, to print it as a table
2. Solution – simple print, with line breaks and such
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
January 11, 2017 at 5:12 pm #11569The second one works out great! Is there a way to limit it to specific attributes. I would prefer to only show Author, ISBN and Publisher?
January 11, 2017 at 5:55 pm #11572I think so. I’ve added an additional variable $allowed_attributes to the code below (line 8). I typed in the labels you need, but please check it if it’s correct. The code is now:
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
January 11, 2017 at 6:41 pm #11576Unfortunately, that still displays all of the attributes, not just the ones allowed. It’s not a major issue. Just something that would be nice. 🙂 No worries.
January 11, 2017 at 6:59 pm #11579I think I know why. I have made a mistake to check only the taxonomy type labels. Here is a correction, worth a final try:
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
January 11, 2017 at 7:22 pm #11580Works beautifully! Thank you!
January 11, 2017 at 7:41 pm #11581You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
The topic ‘Add Specific Product Attribute to Title in Drop Down Display’ is closed to new replies.