Changing Simple products to Variable products
To change from “Simple” to “Variable” you can follow these steps. Note that Variable products use the Attributes to generate the variations. You can use the bulk editor to add the attributes at the same time as changing the type so that it will automatically create the variations.
1. Open the bulk editor and filter the products you want to see.
2. Click on the Type column and then “Edit All Checked Products”
3. Change the type from Simple to Variable:
4. Click on Apply and you can preview the changes:
5. Next, add the Attributes that will be used for the variations. In this example we are using the “Color” attribute:
6. Finally, check the box that says “Automatically create Variations”:
7. If everything looks good, click on the “Save Changes” button. The Simple products will become Variable products and the Variations will be created based upon the Attributes.
By default, the new Variations will not have a price set. You can use the bulk editor to set the prices or if you would like to automatically copy over the Regular Price value from the Simple product to the Variations, you can create a snippet by following these steps:
1. Download the free Code Snippets plugin: https://wordpress.org/plugins/code-snippets/
2. Create a Snippet with the following code:
function custom_pwbe_variation_created( $variation_id, $product_id ) { $simple_product_price = get_post_meta( $product_id, '_regular_price', true ); if ( empty( $simple_product_price ) ) { $simple_product_price = get_post_meta( $product_id, '_price', true ); } if ( !empty( $simple_product_price ) ) { $variation = wc_get_product( $variation_id ); $variation->set_regular_price( $simple_product_price ); $variation->save(); } } add_filter( 'pwbe_variation_created', 'custom_pwbe_variation_created', 10, 2 );
Note: If you prefer you can add this code to your child theme’s functions.php file instead of using Code Snippets.