• Resolved janrenn

    (@janrenn)


    Hello Damian,

    Thanks for very good, light and customizable plugin! I had only one problem getting to search results inside plugin without rewriting plugin code. Could it be possible to add hook for search results? Something as

    
    ajax-search-for-woocommerce/includes/class-search.php
    
    -		echo json_encode( $output );
    +		echo json_encode( apply_filters( 'dgwt_wcas_search_results', $output ); 
    

    I could be great for e.g. adding simple caching functionality. Thank you very much!

    Caching example with new hook:

    
    //cache ajax search
    //-------------------
    add_action( 'init', function () {
        if ( !empty($_REQUEST[ 'wc-ajax' ]) && $_REQUEST[ 'wc-ajax' ] == 'dgwt_wcas_ajax_search' && !empty($_REQUEST[ 'dgwt_wcas_keyword' ]) ) {
            $url_hash = 'wcas_cache_' . md5( "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" );
            $cached = get_transient( $url_hash );
            if ($cached) {
                wp_send_json($cached);
            }
        }
    } );
    add_action( 'dgwt_wcas_search_results', function ( $output ) {
        $cached = $output;
        $url_hash = 'wcas_cache_' . md5( "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" );
        $cached['cached_as'] = $url_hash;
        set_transient( $url_hash, $cached, 60*60*24 );
        return $output;
    } );
    
    • This topic was modified 6 years, 10 months ago by janrenn.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Damian Góra

    (@damian-gora)

    Thank you,
    Great idea.
    I’m going to add the filter you mentioned in the next plugin release.

    Hi!
    Can you add filter also to result of get_result_details() function in class-result-details.php file?

    Or best, can you add any way to change location of “includes/tmpl/single-product-tax.php” file? I want to modify single-product-tax.php template (I want add stock availability of product in search result details).

    Thanks for your work, your plugin is the best!

    • This reply was modified 6 years, 9 months ago by lnpa.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hook for search results’ is closed to new replies.