0

So I imported more than 6000 products and I'm facing a problem.

The thing is that I didn't have a parent SKU so when I imported all my variations, my first variation took the same SKU as the parent one, so when I update price it's doesn't work for my first variation.

So I would like to just remove the parent sku from all my variations and replace it by blank or random.

Is it possible or I have to reimport everything?

Thanks in advance.

WebTasmer
  • 3
  • 2
  • Here is example how to access parent sku - https://stackoverflow.com/questions/53887148/generate-the-product-variations-skus-from-woocommerce-parent-variable-sku . All variations and parent sku are with same _sku so to determine which sku you want you can use $product->get_parent_id(). So you can create query to grab all variable products from there loop each product grab that parent ID and with update post meta you can just set empty value. Always do backup before bulk updates. – Snuffy Sep 20 '22 at 10:05

1 Answers1

0

Place the following function in your functions.php . Always do backup before bulk changes. This is tested and works on WP 6.0.2 WC 6.9.2

// Change hook if needed. This will run on each refresh of the website
add_action('init','test');
function test() {
    // Get variable products.
    $args = array(
        'type' => 'variable',
        'return' => 'ids',
    );
    $product_ids = wc_get_products( $args );
    foreach($product_ids as $product_id) {
        // Get the current parent sku 
        $main_sku = get_post_meta( $product_id, '_sku', true );
        // If not empty clear it
        if(!empty($main_sku)) {
            update_post_meta($product_id, '_sku', '');
        }
    }
}
Snuffy
  • 1,723
  • 1
  • 5
  • 9