• Resolved Leandro

    (@leandroprz)


    Hi,

    I have a video category on my WooCommerce store and I’ve added a div to wrap the thumbnails in order to add a play button on top of the thumbnails.

    I was wondering if it’s possible to do the same to the images in my search results? Maybe with a hook or something else?

    I just need the play button to be on top of certain categories, not all of them.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi,

    There is a hook actually: asl_result_css_class

    You can use it like:

    add_filter('asl_result_css_class', 'my_asl_result_css_class', 10, 1);
    function my_asl_result_css_class($classes) {
    	$my_classes = 'class1 class2';
    	
    	return $my_classes . ' ' . $classes;
    }

    Best,
    Ernest M.

    Thread Starter Leandro

    (@leandroprz)

    That’s awesome! I just tried it and it works fine.

    But I’m having issues using conditionals to add the class only to a particular WooCommerce category.

    I’ve tried all these conditionals but none is working:

    if ( has_term( array ('timelapse', 'timelapse-en'), 'product_cat' ) || is_product_category( array ('434', '1026') ) || cat_is_ancestor_of( array (434, 1026), get_queried_object()->term_id ) )

    I know they are working with other hooks, just not with your plugin.

    Also, I noticed the plugin creates the asl_r_product class. Would it be possible to create another class to every category the product is in? Maybe that’s another solution that could work.

    Thank you

    Plugin Author wpdreams

    (@wpdreams)

    Well, that is not within a regular loop, so that would not work. Unfortunately that filter does not pass on the result arguments either, I forgot to add that.

    I think the best solution would be to correct that filter via editing the plugin code, and I will also make that change in the upcoming release. For that, please replace the wp-content/plugins/ajax-search-lite/includes/views/result.php file in the plugin folder with this.

    Then, you can change the filter to use 3 arguments:

    add_filter('asl_result_css_class', 'my_asl_result_css_class', 10, 3);
    function my_asl_result_css_class($classes, $id, $result) {
    	$my_classes = 'class1 class2';
    	
    	return $my_classes . ' ' . $classes;
    }

    $id -> the post type ID
    $result -> a custom stdClass result object (not WP_Post), containing these fields:

    (
        [title] => Result title
        [id] => 1
        [date] => July 7, 2020 8:22 am
        [content] => Short post content..
        [excerpt] => 
        [content_type] => pagepost
        [author] => admin
        [post_type] => page
        [relevance] => 1
        [link] => https://yoursite.com/sample-page/
        [image] => https://yoursite.com/wp-content/plugins/ajax-search-lite/img/default.jpg
    )

    That should give you more control, and use API functions via the $id variable where needed.

    • This reply was modified 3 years, 11 months ago by wpdreams. Reason: typos
    Thread Starter Leandro

    (@leandroprz)

    Thank you! I’ll look into this.

    • This reply was modified 3 years, 11 months ago by Leandro.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add a div wrapper to results based on WooCommerce category’ is closed to new replies.