Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Add Specific Product Attribute to Title in Drop Down Display
- This topic has 7 replies, 2 voices, and was last updated 9 years, 4 months ago by
Ernest Marcinko.
-
AuthorPosts
-
January 7, 2017 at 10:29 pm #11492
littlefishweb
ParticipantI 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.
January 10, 2017 at 4:25 pm #11532Ernest Marcinko
KeymasterHi!
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
January 11, 2017 at 5:12 pm #11569littlefishweb
ParticipantThe 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 #11572Ernest Marcinko
KeymasterI 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:
January 11, 2017 at 6:41 pm #11576littlefishweb
ParticipantUnfortunately, 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 #11579Ernest Marcinko
KeymasterI think I know why. I have made a mistake to check only the taxonomy type labels. Here is a correction, worth a final try:
January 11, 2017 at 7:22 pm #11580littlefishweb
ParticipantWorks beautifully! Thank you!
January 11, 2017 at 7:41 pm #11581Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- The topic ‘Add Specific Product Attribute to Title in Drop Down Display’ is closed to new replies.