From 3d48400c0bc172d69aa491352677308f5befae67 Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <reinhold@kainhofer.com>
Date: Sun, 28 Jan 2018 21:49:15 +0100
Subject: [PATCH] Fix compat with WC vendors and product variations (variations
 do not have any post_author, so we need to use the parent product in this
 case...

---
 includes/rules_shipping_framework_woocommerce.php | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/includes/rules_shipping_framework_woocommerce.php b/includes/rules_shipping_framework_woocommerce.php
index f0c75f2..330746c 100644
--- a/includes/rules_shipping_framework_woocommerce.php
+++ b/includes/rules_shipping_framework_woocommerce.php
@@ -234,7 +234,14 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework {
 		if (class_exists("WC_Vendors")) {
 			$vendorids = array();
 			foreach ($products as $product) {
-				$vendorids[] = $product['data']->post->post_author;
+				// Variations inherit the vendor from their parent product 
+				if (!isset($product['variation_id'])) {
+					// "Normal" product, not a variation
+					$vendorids[] = $product['data']->post->post_author;
+				} else {
+					// A variation => load the parent product instead and use its vendor
+					$vendorids[] = get_post_field('post_author', $product['product_id']);
+				}
 			}
 			$data['vendorids'] = array_unique($vendorids);
 			
-- 
GitLab