• Hello,

    I already wrote to you 6 months ago about problem with duplicated variations in woocommerce products. (https://wordpress.org/support/topic/duplicated-product-variations-in-woocommerce/) but you never gave me reply and help me with that. I will write it again:

    We are using ERP system to manage products outside WordPress and because of that i needed to write plugin to import products and variations from ERP into Woocommerce. As you can see below I am using standard functions to create new variation for product:

    private function insert_variation(){
        $attributes = Helper::get_variation_attributes($this->product_data['attributes']);
        $variation = new \WC_Product_Variation();
        $variation->set_sku($this->product_code);
        $variation->set_parent_id($this->parent_id);
        $variation->set_attributes($attributes);
        $variation->set_name($this->product_data['title']);
        $variation->set_manage_stock(true);
    
        $this->variation_id = $variation->save();
    
        $product = wc_get_product($this->parent_id);
        $product->sync($this->variation_id, true);
    }

    This is also how i create product for this variations:

    private function insert_product(){
        $product = new \WC_Product_Variable();
        $product->set_name($this->product_data['title']);
        $product->set_sku($this->product_data['sku']);
        $product->set_status('draft');
        if($this->product_data['luxury']){
           $product->set_category_ids(array($this->assign_to_luxury()));
        }
    
        $this->product_id = $product->save();
    
        pll_set_post_language($this->product_id, 'pl');
        $this->create_translations();
    }

    And after I create product or variation I’m creating translations of this product by:

    private function create_translations(){
        $languages = Helper::get_languages();
        $wc_apd = new \WC_Admin_Duplicate_Product();
        $translations = array('pl' => $this->product_id);
        if(!empty($languages)){
            add_filter( 'wc_product_has_unique_sku', '__return_false' );
            foreach ($languages as $lang){
                if($lang == 'pl') continue;
                $duplicated_product = $wc_apd->product_duplicate(wc_get_product($this->product_id));
                pll_set_post_language($duplicated_product->get_id(), $lang);
                $translations[$lang] = $duplicated_product->get_id();
            }
            remove_filter( 'wc_product_has_unique_sku', '__return_false' );
            pll_save_post_translations($translations);
        }
    }

    Polish version of products is default and I assign it right after creating product.

    And here the fun begin… Products and variations are created correctly and saved as drafts. But after I change product description or other fields and then save it variations create their duplicates.

    We are using:

    • Woocommerce – in latest version (7.3)
    • Polylang for WooCommerce – in latest version (1.6.3)
    • Polylang Pro – in latest version as well (3.2.5)
Viewing 1 replies (of 1 total)
  • Thread Starter pwasielewski

    (@pwasielewski)

    Hi,

    I still hasn’t got any answer yet… Can anyone look into this case and tell me anything what could i do to fix that?

    Here is an example what i’ve got after saving post in specyfic language:

Viewing 1 replies (of 1 total)
  • The topic ‘Duplicated WC variations in polylang’ is closed to new replies.