Convert WordPress posts to products in WooCommerce

The question:

Is there anyway I could convert all the posts e have right now on our WordPress install into products using some MySQL query or something like that?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

You could install the Post Type Switcher plugin

Or Run SQL query on your database to change the post to product post type

UPDATE  `wp_posts` SET  `post_type` =  'product' WHERE  `post_type` = 'post';

Backup your DB 1st.

UPDATE  `wp_posts` SET  `post_type` =  'wpsc-product' WHERE  `post_type` = 'post';

Method 2

You can update the post_type in mysql table wp_posts update the post_type to product

sample query UPDATE wp_posts SET post_type = 'product' WHERE post_type = 'post';

Method 3

Please use $wpdb to interact with the Database.

global $wpdb;
$wpdb->update(
    // Table name
    $wpdb->posts,
    // New values
    array( 'post_type' => 'product', ),
    // SQL "WHERE" clause base / affected rows
    array( 'post_type' => 'post', ),
    // Data Type (available: %s string, %d integer, %f float)
    '%s',
    // SQL "WHERE" clause Type
    '%s'
);

Keep in mind that this query will change the post_type of every post to product. Having a backup of your DB before doing this is recommended. It would be even better if you use a (local) test installation and refine your update process there.

More info about updating rows in the DB.

A detailed Guide on How To handle MySQL on the Command Line can be found in this extensive meta post.

Method 4

Additionally (optional): SQL query for converting the categories to product_cat

UPDATE `wp_term_taxonomy` SET `taxonomy`='product_cat' WHERE `taxonomy`='category'

Method 5

I used https://wpsheeteditor.com/. the other solutions were great if you wanted to do all pages, I’d have done the SQL query, but there were about 30 pages that needed doing and 40 that didn’t. Even if a few just needed to be changed back I’d have done that but this sheet editor plugin was a huge help.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment