Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created March 9, 2022 16:41
Show Gist options
  • Save searchwpgists/170dcdf216b60020a8ba106a446eed59 to your computer and use it in GitHub Desktop.
Save searchwpgists/170dcdf216b60020a8ba106a446eed59 to your computer and use it in GitHub Desktop.
Make WooCommerce Order Notes searchable by SearchWP
<?php
// Make WooCommerce Order Notes searchable by SearchWP.
// @link https://searchwp.com/documentation/knowledge-base/search-woocommerce-orders/
add_action( 'searchwp\source\post\attributes\comments', function() {
if ( did_action( 'searchwp\indexer\batch' ) ) {
remove_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] );
}
} );
// Add Order Notes to SearchWP's Comments Source.
add_filter( 'searchwp\source\comment\db_where', function( $db_where, $source ) {
$db_where[0]['value'] = [ 'comment', 'order_note', ];
$db_where[0]['compare'] = 'IN';
return $db_where;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment