Created
September 13, 2020 04:49
-
-
Save git-bhanu/47dc0a02a9c158f72f385352ed6bab2e to your computer and use it in GitHub Desktop.
Relevanssi Customcode settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Enable one letter search | |
| add_filter('relevanssi_block_one_letter_searches', __NAMESPACE__.'\\one_word_searches'); | |
| function one_word_searches() { | |
| return false; | |
| } | |
| // https://www.relevanssi.com/knowledge-base/indexing-product-variation-skus-main-product/ | |
| add_filter( 'relevanssi_content_to_index', __NAMESPACE__.'\\rlv_index_variation_skus', 10, 2 ); | |
| function rlv_index_variation_skus( $content, $post ) { | |
| if ( 'product' === $post->post_type ) { | |
| $args = array( | |
| 'post_parent' => $post->ID, | |
| 'post_type' => 'product_variation', | |
| 'posts_per_page' => -1 | |
| ); | |
| $variations = get_posts( $args ); | |
| if ( ! empty( $variations ) ) { | |
| foreach ( $variations as $variation ) { | |
| $sku = get_post_meta( $variation->ID, '_sku', true ); | |
| $content .= " $sku"; | |
| } | |
| } | |
| } | |
| return $content; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment