Skip to main content

Batch script to update WooCommerce product titles

I had a client who had named all of his 600+ products to uppercase and Google Shopping was not allowing the products to be indexed because of this.
To automatically rename the Woocommerce Product titles, I ran this script:

This will loop through each product and rename the titles to capitalised using php UCWORDS()

For example: MY PRODUCT will be renamed to My Product.

$args = array ('post_type' => 'product','posts_per_page' => -1);

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
    while( $query->have_posts() ) {
        $post = get_post();
      $title = ucwords(strtolower($post->post_title));
      $post_update = array(
        'ID'         => $post->ID,
        'post_title' => $title
      wp_update_post( $post_update );
} else {
    // no posts found

Leave a Reply