Hook for search results
-
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; } );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Hook for search results’ is closed to new replies.