• Is it possible to convert my WordPress Posts, including all custom meta, to WooCommerce products? I tried updating post types from post to product in phpMyAdmin using some SQL, but that only converts the basic things like content, title and image. I need all the custom meta to transfer over as well.

Viewing 1 replies (of 1 total)
  • Hello, jordanwebdev

    Please try this code:

        $args = array(
            'post_type' => 'post',
            'post_status' => 'any',
            'numberposts' => -1
        );
    
        $lastposts = get_posts( $args );
        foreach( $lastposts as $post ) : setup_postdata($post);
    
            set_post_type( get_the_ID(), 'product' );
            add_post_meta( get_the_ID(), '_price',         ' >>> PRICE <<< ', true);
            add_post_meta( get_the_ID(), '_regular_price', ' >>> PRICE <<< ', true);
            add_post_meta( get_the_ID(), '_visibility',    'visible', true);
            add_post_meta( get_the_ID(), '_stock_status',  'instock', true);
    
        endforeach;
        wp_reset_postdata();
Viewing 1 replies (of 1 total)
  • The topic ‘Posts to Products?’ is closed to new replies.