PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Update 2.0.5 Single product feature video link not working

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

I have a bunch of simple objects I want to combine into a variation. Not sure if the new feature supports this, so thought I'd look into if the video mentioned in the 2.0.5 update shows this. The link is dead. Is it the same video as on the bulk-editor.com/video page? Just making sure I'm not missing anything important.

Hello

All videos created for BEAR(WOOBE) you can find here https://bulk-editor.com/video

Unfortunately BEAR can't automatically convert simple products into variations because there's no reliable way to determine which attributes (color, size, etc.) each product should have - they're just in the product titles as text.

However, I can provide you with a PHP function that you can add to your theme's functions.php. You'll manually specify which simple products should become variations and their attributes, then call it once via URL.

Here's the function:

// Add to functions.php
add_action('init', function() {
    if (isset($_GET['convert_to_variable']) && $_GET['secret_key'] === 'YOUR_SECRET_KEY_HERE') {
        
        // Define your conversion data
        $conversion_data = [
            123 => [ // Simple product ID
                'attributes' => [
                    'color' => ['Red'],
                    'size' => ['XL']
                ],
                'price' => 29.99,
                'stock' => 10
            ],
            124 => [
                'attributes' => [
                    'color' => ['Blue'],
                    'size' => ['M']
                ],
                'price' => 27.99,
                'stock' => 15
            ],
            // Add more products...
        ];
        
        $parent_name = 'T-Shirt'; // Name for the variable product
        
        // Create variable product
        $parent_id = wp_insert_post([
            'post_title' => $parent_name,
            'post_type' => 'product',
            'post_status' => 'publish'
        ]);
        
        wp_set_object_terms($parent_id, 'variable', 'product_type');
        
        // Collect all unique attributes
        $all_attributes = [];
        foreach ($conversion_data as $data) {
            foreach ($data['attributes'] as $attr_name => $values) {
                if (!isset($all_attributes[$attr_name])) {
                    $all_attributes[$attr_name] = [];
                }
                $all_attributes[$attr_name] = array_merge($all_attributes[$attr_name], $values);
            }
        }
        
        // Create attributes for parent product
        $product_attributes = [];
        foreach ($all_attributes as $attr_name => $values) {
            $values = array_unique($values);
            
            $attribute = new WC_Product_Attribute();
            $attribute->set_name($attr_name);
            $attribute->set_options($values);
            $attribute->set_visible(true);
            $attribute->set_variation(true);
            $product_attributes[] = $attribute;
        }
        
        $parent_product = wc_get_product($parent_id);
        $parent_product->set_attributes($product_attributes);
        $parent_product->save();
        
        // Create variations
        foreach ($conversion_data as $simple_id => $data) {
            $variation = new WC_Product_Variation();
            $variation->set_parent_id($parent_id);
            
            // Set attributes
            $variation_attributes = [];
            foreach ($data['attributes'] as $attr_name => $values) {
                $variation_attributes[$attr_name] = $values[0];
            }
            $variation->set_attributes($variation_attributes);
            
            // Set price
            if (isset($data['price'])) {
                $variation->set_regular_price($data['price']);
            }
            
            // Set stock
            if (isset($data['stock'])) {
                $variation->set_stock_quantity($data['stock']);
                $variation->set_manage_stock(true);
            }
            
            $variation->save();
            
            // Optional: delete or draft the old simple product
            // wp_update_post(['ID' => $simple_id, 'post_status' => 'draft']);
        }
        
        wp_die('Variable product created! ID: ' . $parent_id);
    }
});

Usage: 1. Change YOUR_SECRET_KEY_HERE to something random 2. Fill in the $conversion_data array with your product IDs and attributes 3. Visit: yoursite.com/?convert_to_variable=1&secret_key=YOUR_SECRET_KEY_HERE 4. Remove the code after conversion

Let me know if you need any adjustments!