Skip to content

Instantly share code, notes, and snippets.

@geotsiokos
Created November 11, 2021 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geotsiokos/ba144e6169835670317f81680c444583 to your computer and use it in GitHub Desktop.
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
// 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