/** * Sync all inventory from Square (expensive) * @todo if searching for square id fails, check for SKU */ public function sync_all_inventory() { // refresh cache first to get the latest inventory $this->connect->refresh_inventory_cache(); $square_inventory = $this->connect->get_square_inventory(); // hopefully there has been a manual sync prior so that square item id // has already been saved in the product/variation metas to prevent // unnecessary round trip requests to Square to find the SKU foreach ($square_inventory as $variation_id => $stock) { $wc_product = WC_Square_Utils::get_wc_product_for_square_item_variation_id($variation_id); if (is_object($wc_product)) { $wc_product->set_stock((int) $stock); } } return true; }