Add Specific Product Attribute to Title in Drop Down Display

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 Ernest Marcinko 7 years, 3 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #11492
    littlefishweb
    littlefishweb
    Participant

    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.
    #11532
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    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 :)


    #11569
    littlefishweb
    littlefishweb
    Participant

    The 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?

    #11572
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I 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 :)


    #11576
    littlefishweb
    littlefishweb
    Participant

    Unfortunately, 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.

    #11579
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I 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 :)


    #11580
    littlefishweb
    littlefishweb
    Participant

    Works beautifully! Thank you!

    #11581
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Add Specific Product Attribute to Title in Drop Down Display’ is closed to new replies.