Frustrated with the latest updates that cause your product catalog to no longer be allowed to Check on your website, and in order for your products to stay on Facebook and Instagram shops you need to enable Checkout on Facebook/Instagram. However the official Facebook for WooCommerce plugin created by Facebook says it doesn’t support it. We created a couple lines of code to add to your plugin that adds a stock level of 10000 to every product that you have set to sync. Check it out below:
Add Quantity to Sell on Facebook functionality to Facebook for WooCommerce plugin
(around line 789)
// Locate the prepare_product_data_items_batch method in the WC_Facebookcommerce_Utils class
public static function prepare_product_data_items_batch($product) {
$fb_product = new \WC_Facebook_Product($product->get_id());
$data = $fb_product->prepare_product(null, \WC_Facebook_Product::PRODUCT_PREP_TYPE_ITEMS_BATCH);
// Add the "quantity to sell on Facebook" field with a value of 100 or whatever stock level you wish
$data['quantity_to_sell_on_facebook'] = 100;
$data['item_group_id'] = $data['retailer_id'];
return self::normalize_product_data_for_items_batch($data);
}
and Add Quantity to Sell on Facebook to Variations:
(around line 850)
// Locate the prepare_product_variation_data_items_batch method in the WC_Facebookcommerce_Utils class
public static function prepare_product_variation_data_items_batch($product) {
$parent_product = wc_get_product($product->get_parent_id());
if (!$parent_product instanceof \WC_Product) {
throw new PluginException("No parent product found with ID equal to {$product->get_parent_id()}.");
}
$fb_parent_product = new \WC_Facebook_Product($parent_product->get_id());
$fb_product = new \WC_Facebook_Product($product->get_id(), $fb_parent_product);
$data = $fb_product->prepare_product(null, \WC_Facebook_Product::PRODUCT_PREP_TYPE_ITEMS_BATCH);
// Set the "quantity to sell on Facebook" field to 10000 for each variation
$data['quantity_to_sell_on_facebook'] = 10000;
$data['item_group_id'] = \WC_Facebookcommerce_Utils::get_fb_retailer_id($parent_product);
return self::normalize_product_data_for_items_batch($data);
}