-
-
Save searchwpgists/a1aa4ddca16ba59067f15ac912950852 to your computer and use it in GitHub Desktop.
Include product SKU in Live Search result content
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
| <?php | |
| add_filter( 'searchwp_live_search_results_entry_data', function( $data, $result ) { | |
| if ( $result instanceof \WP_Post && $result->post_type === 'product' ) { | |
| $sku = get_post_meta( $result->ID, '_sku', true ); | |
| if ( ! empty( $sku ) ) { | |
| $data['content'] .= '<p><strong>SKU:</strong> ' . esc_html( $sku ) . '</p>'; | |
| } | |
| } | |
| return $data; | |
| }, 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment