Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is trying to synchronize product stock statuses across translations in a WordPress site using WPML. They imported products using WP All Import, and while the stock quantities sync correctly, the stock statuses do not. Translated products remain marked as 'In stock' even with 0 quantity.
Solution:
If manually updating each product is not feasible due to the large number of products, we recommend implementing a custom code solution. Here are the steps to follow:
1) Ensure you back up your site before proceeding.
2) Add the following code snippet to the end of the functions.php file of your active theme:

add_action('admin_init', function () {
    // Only run for admins
    if (!current_user_can('manage_woocommerce')) {
        return;
    }
 
    // Fetch all published product IDs
    $product_ids = get_posts([
        'post_type'      => 'product',
        'post_status'    => 'publish',
        'posts_per_page' => -1,
        'fields'         => 'ids',
    ]);
 
    foreach ($product_ids as $product_id) {
        $product = wc_get_product($product_id);
        if ($product) {
            $product->save(); // Re-saves the product, triggering related hooks
        }
    }
 
    echo '<div class="notice notice-success is-dismissible"><p>All published products have been re-saved.</p></div>';
});

3) Visit any page in your WP Admin (like Dashboard or Products page) to trigger the script.
4) Once the script completes and shows a success notice, remove the snippet from your functions.php file.
This solution requires some technical knowledge, and it's recommended for a web developer to implement it. Additionally, consider using the WPML Export & Import addon for similar tasks.

If this solution does not apply to your case, or if it seems outdated, please check the related known issues and confirm that you have installed the latest versions of themes and plugins. If the issue persists, we highly recommend opening a new support ticket at WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 3 replies, has 1 voice.

Last updated by Andreas W. 2 months, 3 weeks ago.

Assisted by: Andreas W..

Author Posts
April 24, 2025 at 1:15 pm #16964595

brankoK

Background of the issue:
I am trying to sync product stock statuses across translations on my WordPress site using WPML. I imported products using WP All Import, and while the stock quantities are syncing correctly, the stock statuses are not.

Symptoms:
Translated products remain marked as 'In stock' even with 0 quantity, despite running 'Sync stock and status' from WooCommerce Multilingual & Multicurrency > Troubleshooting.

Questions:
How can I ensure that the stock status is properly synced to translated products?

April 24, 2025 at 5:48 pm #16965771

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

Could you please confirm if these are variable products?

In the meantime, while one of my colleagues is being assigned to your ticket, we recommend reviewing the following open errata that may be relevant to the issue you're experiencing and trying the workaround.

https://wpml.org/errata/woocommerce-multilingual-product-variations-with-price-set-to-0-show-as-out-of-stock-in-secondary-languages/

Let us know your results, please.

April 24, 2025 at 8:53 pm #16966340

brankoK

Hi Bobby,

We're not using any variable products or product variations.

I remember that we've had this issue in the past, and I know one way to to fix it: Manually saving/updating the products in the original language.

However, we have +4000 products on the website so that would take a few hours/days to complete. Therefore, I would like a more efficient solution.

Looking forward to your insights.

Kind regards,

Branko

April 25, 2025 at 2:22 am #16966570

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

If you do not want to go through all the products using Woocommerce's bulk edit option, you can only achieve this with code.

Example:

Please take a backup of your site before proceeding.

add_action('admin_init', function () {
    // Only run for admins
    if (!current_user_can('manage_woocommerce')) {
        return;
    }

    // Fetch all published product IDs
    $product_ids = get_posts([
        'post_type'      => 'product',
        'post_status'    => 'publish',
        'posts_per_page' => -1,
        'fields'         => 'ids',
    ]);

    foreach ($product_ids as $product_id) {
        $product = wc_get_product($product_id);
        if ($product) {
            $product->save(); // Re-saves the product, triggering related hooks
        }
    }

    echo '<div class="notice notice-success is-dismissible"><p>All published products have been re-saved.</p></div>';
});

1) Add the snippet to the end of the functions.php file of your active theme

2) Go to any page in your WP Admin (like Dashboard or Products page).

3) Wait for it to finish (it’ll show a success notice).

4) Remove the snippet right after it runs.

Note, that this is usually a topic for a web developer, and our support team is not obligated to provide any custom solutions. We usually can only support options and features that are available inside WPML.

Also, note that we offer the addon "WPML Export & Import" for such use cases.
https://wpml.org/documentation/related-projects/wpml-export-and-import/

Best regards
Andreas