I'm trying to modify the SKUs displayed on the product pages of variable products. The SKUs are in the format "text1.text2.text3". The texts can contain all letters and numbers and are of variable length. On the product page, I only want to display text1.text2 as SKU.
I came up with the following code so far that I included in the functions.php of my theme (Avada). However, the SKU output doesn't change. Are there any pointers you could give me? I'm not sure if I'm using the correct hook.
add_action( 'avada_woocommerce_before_product_summary', 'modifySKU' );
function modifySKU( $atts )
{
global $product;
$atts = shortcode_atts( array( 'id' => '', ), $atts );
// If there is no ID, we are already on a product page
if (empty( $atts['id'] ) )
{
$sku = $product->get_sku();
// new array $output_array();
preg_match("/[^\.]*\.[^\.]*/", $sku, $output_array);
$sku = reset($output_array);
return $sku;
}
}