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 2 months, 3 weeks ago.
Assisted by: Andreas W..