{"id":19014530,"date":"2026-09-08T13:37:14","date_gmt":"2026-09-08T13:37:14","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/stock-synchronization-3\/"},"modified":"2026-09-08T13:37:14","modified_gmt":"2026-09-08T13:37:14","slug":"stock-synchronization-3","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/stock-synchronization-3\/","title":{"rendered":"stock synchronization"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hello,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I am using Inventory Sync for WooCommerce Free 2.1.1 to synchronize stock between two independent WooCommerce stores.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have found a problem with stock synchronization for variable products.The problem<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Manual changes to a variation&#8217;s stock are synchronized correctly between the two stores.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, when a customer purchases a variation, WooCommerce correctly reduces the stock on the source store, but the stock is not updated on the other store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<ul>\n<li>Store A variation SKU: <code>LOR-GRN-42<\/code><\/li>\n\n\n\n<li>Store B has the same variation SKU: <code>LOR-GRN-42<\/code><\/li>\n\n\n\n<li>Stock on Store A: 10<\/li>\n\n\n\n<li>Customer purchases 1 item<\/li>\n\n\n\n<li>Store A correctly changes to 9<\/li>\n\n\n\n<li>Store B remains at 10<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The same variation synchronizes correctly when I manually change its stock in the WooCommerce admin.What I found in the code<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After investigating version 2.1.1, it appears that the order synchronization code handles variations differently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In <code>format_order_items()<\/code>, the parent product ID from the source store is used when building the synchronization data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if ( $parent_id = $product-&gt;get_parent_id() ) {\n    $return&#091;'variations']&#091;$parent_id]&#091;] = $this-&gt;product_data( $product, $woocommerce );\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Later, this parent ID is used when updating the variation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$woocommerce-&gt;put(\n    \"products\/{$parent_id}\/variations\/{$variation_id}\",\n    $variations&#091;0]\n);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The problem is that the parent product ID belongs to the source WooCommerce installation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On two independently created WooCommerce stores, the same product normally has different database IDs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Therefore, using the source store&#8217;s parent ID when making the REST API request to the destination store can cause the variation update to fail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Interestingly, the exception is also caught without logging:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>catch ( Exception $e ) {\n    \/\/ TODO logger\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This makes the problem difficult to diagnose because there is no useful error in the WooCommerce logs.Workaround<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I tested a workaround that searches for both the parent product and the variation in the destination store by SKU and then uses the destination store&#8217;s IDs for the REST API request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With this approach, stock synchronization after a purchase works correctly in both directions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So the issue appears to be specifically related to variation order synchronization when the two stores have different product\/parent IDs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Could you please check this part of the 2.1.1 code and confirm whether this is a bug?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If so, it would be great if it could be fixed in a future version.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"template":"","class_list":["post-19014530","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19014530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19014530\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=19014530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}