Может кому пригодится (если товаров много увеличьте time_limit):
add_filter( 'init', 'sku_from_title_and_variation', 10, 1);
function sku_from_title_and_variation(){
set_time_limit(300);
$query = array(
'numberposts' => -1,
'post_status' => 'published',
);
$products = wc_get_products( $query );
foreach ($products as $product) {
if( $product->is_type('variable') ){
$product_id = $product->get_id();
$product_title = $product->get_title();
update_post_meta( $product_id, '_sku', $product_title );
wc_delete_product_transients( $product_id );
foreach( $product->get_available_variations() as $variation_values ){
$variation_id = $variation_values['variation_id']; // variation id
$variation_attr = $variation_values['attributes'];
$variation_attr = $variation_attr['attribute_pa_variant'];
$variation_attr = get_term_by('slug', $variation_attr , 'pa_variant')->name;
update_post_meta( $variation_id, '_sku', $product_title.$variation_attr );
wc_delete_product_transients( $variation_id );
}
wc_delete_product_transients( $product->get_id() );
} else {
update_post_meta( $product->get_id(), '_sku', $product->get_title());
wc_delete_product_transients( $product->get_id() );
}
}
}