/** * Sync a WC Product to Square, optionally including Categories and Inventory. * * @param WC_Product $wc_product * @param bool $include_category * @param bool $include_inventory * @param bool $include_image */ public function sync_product(WC_Product $wc_product, $include_category = false, $include_inventory = false, $include_image = false) { // Only sync products with a SKU $wc_product_skus = WC_Square_Utils::get_wc_product_skus($wc_product); if (empty($wc_product_skus)) { WC_Square_Sync_Logger::log(sprintf('[WC -> Square] Skipping WC Product %d since it has no SKUs.', $wc_product->id)); return; } // Look for a Square Item with a matching SKU $square_item = $this->get_square_item_for_wc_product($wc_product); // SKU found, update Item if (WC_Square_Utils::is_square_item_found($square_item)) { $result = $this->update_product($wc_product, $square_item, $include_category, $include_inventory); // No SKU found, create new Item } else { $result = $this->create_product($wc_product, $include_category, $include_inventory); } // Sync inventory if create/update was successful // TODO: consider whether or not this should be part of sync_product().. if ($result) { if ($include_inventory) { $this->sync_inventory($wc_product); } if ($include_image) { $this->sync_product_image($wc_product, $result); } } else { WC_Square_Sync_Logger::log(sprintf('[WC -> Square] Error syncing WC Product %d.', $wc_product->id)); } }