This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

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

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #11492
    littlefishweblittlefishweb
    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.

    #11532
    Ernest MarcinkoErnest 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

    #11569
    littlefishweblittlefishweb
    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 MarcinkoErnest 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:

    #11576
    littlefishweblittlefishweb
    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 MarcinkoErnest 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:

    #11580
    littlefishweblittlefishweb
    Participant

    Works beautifully! Thank you!

    #11581
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

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.