Convert from Portfolio post to WooCommerce products [closed]

Yes, there are plugins and code snippets available that can help you turn portfolio posts into WooCommerce products at once.

One such plugin is the “Portfolio to WooCommerce Product Converter” plugin, which can convert all your portfolio posts into WooCommerce products with just a few clicks. Once the plugin is installed and activated, you can simply select the portfolio posts you want to convert and click the “Convert to Product” button.

Alternatively, you can also use a code snippet to achieve the same result. Here is an example code snippet that you can use:

// Get all portfolio posts
$args = array(
  'post_type' => 'portfolio',
  'posts_per_page' => -1
);
$portfolio_posts = new WP_Query( $args );

// Loop through each post and convert to product
if ( $portfolio_posts->have_posts() ) {
  while ( $portfolio_posts->have_posts() ) {
    $portfolio_posts->the_post();
    $product = wc_get_product( get_the_ID() );
    if ( ! $product ) {
      $product = new WC_Product();
      $product->set_name( get_the_title() );
      $product->set_status( 'publish' );
      $product->set_regular_price( '0' );
      $product->set_manage_stock( true );
      $product->set_stock_quantity( 100 );
      $product->set_stock_status( 'instock' );
      $product->set_sku( 'portfolio_' . get_the_ID() );
      $product->set_description( get_the_content() );
      $product->set_short_description( get_the_excerpt() );
      $product->set_category_ids( wp_get_post_terms( get_the_ID(), 'portfolio_category', array( 'fields' => 'ids' ) ) );
      $product->set_featured( true );
      $product->save();
    }
  }
  wp_reset_postdata();
}

You can add this code snippet to your functions.php file or create a custom plugin to run it. It will loop through all your portfolio posts, create a new WooCommerce product for each post, and set the necessary product attributes such as name, price, SKU, category, etc.

Please note that before running this code, you should backup your website and test it on a staging site to ensure that everything works correctly.