Created
November 11, 2021 21:26
-
-
Save geotsiokos/ba144e6169835670317f81680c444583 to your computer and use it in GitHub Desktop.
Adds a hyphen to the product SKU right after three characters starting from the left
This file contains 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
// Adds a hyphen to the product SKU right after three characters starting from the left | |
add_filter ( 'woocommerce_product_search_indexer_filter_content', 'example_woocommerce_product_search_indexer_filter_content', 10, 3 ); | |
function example_woocommerce_product_search_indexer_filter_content( $content, $context, $post_id ) { | |
if ( $context === 'post_content' ) { | |
$product = wc_get_product( $post_id ); | |
if ( $product ) { | |
$product_sku = $product->get_sku(); | |
$alternative_product_sku = substr_replace( $product_sku, '-', 3, 0 ); | |
$content .= ' ' . $alternative_product_sku; | |
} | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment