从 WooCommerce 3 开始,要更改现有产品的产品类型,您可以使用以下命令:/** * Change product type. * * @param int $product_id - The product id. * @param string $new_product_type - The new product type */ // Get the correct product classname from the new product type$product_classname = WC_Product_Factory::get_product_classname( $product_id, $new_product_type );// Get the new product object from the correct classname$new_product = new $product_classname( $product_id );// Save product to database and sync caches$new_product->save();