From 0d844af015777e47724551ea19dc1124bd2c217f Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <reinhold@kainhofer.com>
Date: Wed, 24 Feb 2016 15:52:15 +0100
Subject: [PATCH] Add support for YITH WooCommerce Multi Vendors

---
 .../rules_shipping_framework_woocommerce.php  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/includes/rules_shipping_framework_woocommerce.php b/includes/rules_shipping_framework_woocommerce.php
index d168b03..ca99e0b 100644
--- a/includes/rules_shipping_framework_woocommerce.php
+++ b/includes/rules_shipping_framework_woocommerce.php
@@ -259,6 +259,27 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework {
 			$data['vendorids'] = array_unique($vendorids);
 		}
 		
+		// "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy)
+		if (function_exists("yith_get_vendor")) {
+			$vendors = array();
+			$vendornames = array();
+			$vendorids = array();
+			// The plugin provides its own function to retrieve the vendor for a product
+			foreach ($products as $product) {
+				$vendor = yith_get_vendor($product['data']->id, 'product');
+// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>");
+				if ($vendor->is_valid()) {
+					$vendors[] = $vendor->slug;
+					$vendornames[] = $vendor->name;
+					$vendorids[] = $vendor->term_id;
+				}
+			}
+			$data['vendors'] = array_unique($vendors);
+			$data['vendornames'] = array_unique($vendornames);
+			$data['vendorids'] = array_unique($vendorids);
+		}
+		
+		
 		// END THIRD-PARTY SUPPORT
 		
 		
@@ -392,6 +413,15 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework {
 						$vnd_props[] = $vendor->slug;
 					}
 				}
+
+				// "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy)
+				if (function_exists("yith_get_vendor")) {
+					$vendor = yith_get_vendor($p['data']->id, 'product');
+					if ($vendor->is_valid()) {
+						$vnd_props[] = $vendor->slug;
+					}
+				}
+		
 				// END THIRD-PARTY SUPPORT
 
 				// Check if any of the vendor properties is matched by the conditions; If not => skip product
-- 
GitLab