0

When performing batch automatic product synchronization with Polylang, it only syncs the first product.

\`function auto_translate($post_id, $post, $update)
{
if (!$update) {
return;
}

    // prevent creation of additional duplicate draft posts
    if ( $post->post_status == 'draft' ){
        return;
    }
    
    // prevent recursion when publishing translations
    remove_action('save_post', 'auto_translate', 999, 3);
    
    global $polylang;
    $langs = ['ru'];
    $current_translations = pll_get_post_translations($post_id);
    $post_type = get_post_type($post_id);
    
    if ($post_type == 'product') {
        foreach ($langs as $lang) {
            if (!isset($current_translations[$lang])) {
                $polylang->sync_post_model->copy_post($post_id, $lang, true);
            }
        }
    }

}

// needs low priority or the synchronisation option wont be saved
add_action('save_post', 'auto_translate', 999, 3);\`

Code that syncs when I update the product.

I got the ids of all products from the database, I am updating from here. But it only synchronizes the first entered id. How can I synchronize all the entered ids?

0 Answers0