• Resolved Goajazzz

    (@goajazzz)


    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,

    There are surely a few ways of doing that, even possibly removing the last word based on your shared pattern.

    Still, that’s odd because adding the SKU to the title is not a native feature for WooCommerce.

    Do you remember how it was added initially? Do you have a specific code on your site adding the title?

    Thread Starter Goajazzz

    (@goajazzz)

    Hi @felipea8c, these SKUs in titles just imported from supplier’s CSV file.

    Hello,

    Can you provide a copy of the supplier’s CSV file at least with one product, that way we can check better, and you can send the Google Docs or dropbox file link.

    Thanks.

    Thread Starter Goajazzz

    (@goajazzz)

    Hi, nothing special in this CSV, just the supplier wrote SKU numbers at the end of each product title. That’s why I need a solution to hide or remove these SKU numbers from titles.

    Hello @goajazzz

    I understand that the SKU numbers were added at the end of each product title on the CSV file.

    As requested earlier, if it is possible to send the CSV file of at least one (1) product for us to check it further and replicate it on our test site as well?

    Looking forward to hearing from you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove SKU at the end of product titles’ is closed to new replies.