Remove SKU at the end of product titles (Woocommerce)

Question

I’m trying to remove SKU at the end of my product titles (e.g. “Good product DFO314” where DFO314 is a SKU and they are all different for each product). What I have tried:

function sku_product__title($title, $id) {
    global $pagenow;
    if ( $pagenow != 'edit.php' && get_post_type( $id ) == 'product' ) {
        if(preg_match('/[^(C375|C377|C378|C379|C380|C381|C382|C383|C385|C386|C387|C388|C389|C390|C434|C435|C436|C437|C438|C439|C440|C441|C442|C443|C444|C445|C446|C447|C448|C449|C450|C451|C461|C462|C463|C464|C465|C466|C467|C468|C469|C470|C471|C472|C473|C474|C475|C476|C477|C478|C480|C481|C482|C483|C484|C485|C486|C487|C488|C489|C490|C491|C492|C493|C494|C495|C496|C497|C498|C500|C501|C502|C504|C505|C507|C509|C510|C511|C512|C513|C514|C515|C517|C518|C520|C521|C522|C525|C528|C529|C530|C531|C532|C533|C534|C535|C536|C538|C539|C540|C542|C543|C545|C546|and so on)]*/', $title, $matches)){
            return trim($matches[0]);
        }else{
            return $title;
        }
    }
    return $title;
}
add_filter('the_title', 'sku_product__title', 10, 2);

But it removes every word with matching letters that is not what I looking for. What to change in this code to remove only SKU as a whole and leave clean title?

0
Artheads 4 days 2022-08-04T15:11:41-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse