diff --git a/Makefile b/Makefile index 05a032bd94c4a2de0a9408e21bf47d08dcd6673c..ad5480626f766ceceb680f0c47d8e4d859077ea1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ BASE=shipping-by-rules PLATTFORM=woocommerce VENDOR=opentools -VERSION=1.1.2 +VERSION=1.2 DIR = $(shell pwd) SVNDIR=wordpress-plugin-svn diff --git a/includes/rules_shipping_framework_woocommerce.php b/includes/rules_shipping_framework_woocommerce.php index 776bc00bf5dc23dee4224d83e2b13bff8a89c95c..d168b038d5980e8288bb3d9e34d3d634810a3cb9 100644 --- a/includes/rules_shipping_framework_woocommerce.php +++ b/includes/rules_shipping_framework_woocommerce.php @@ -22,6 +22,7 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { "subcategories" => 'subcategories', "products" => 'products', "skus" => 'products', + "vendors" => 'vendors', )); } static function getHelper() { @@ -209,13 +210,59 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { $categories = array_unique($categories); $tags = array_unique($tags); $shipping_classes = array_unique($shipping_classes); + - return array ( + $data = array ( 'skus' => $skus, 'categories' => $categories, 'tags' => $tags, 'shippingclasses' => $shipping_classes, ); + + // THIRD-PARTY SUPPORT + + // "WC Vendors" support (vendors stored as post author) + if (class_exists("WC_Vendors")) { + $vendorids = array(); + foreach ($products as $product) { + $vendorids[] = $product['data']->post->post_author; + } + $data['vendorids'] = array_unique($vendorids); + + $vendors = array(); // Requires "WC Vendors" or "WooThemes Product Vendors" plugin + $vendornames = array(); + foreach ($data['vendorids'] as $v) { + $vnd = get_user_by('id', $v); // Get user name by user id + $vendornames[] = $vnd->display_name; + $vendors[] = $vnd->user_login; + } + $data['vendornames'] = array_unique($vendornames); + $data['vendors'] = array_unique($vendors); + } + + // "WooThemes Vendor Products" support (vendors stored in its own taxonomy) + if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) { + $vendors = array(); + $vendornames = array(); + $vendorids = array(); + // The plugin provides its own function to retrieve the vendor for a product + foreach ($products as $product) { + foreach (get_product_vendors($product['data']->id) as $vendor) { +// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>"); + $vendors[] = $vendor->slug; + $vendornames[] = $vendor->title; + $vendorids[] = $vendor->ID; + } + } + $data['vendors'] = array_unique($vendors); + $data['vendornames'] = array_unique($vendornames); + $data['vendorids'] = array_unique($vendorids); + } + + // END THIRD-PARTY SUPPORT + + + return $data; } protected function getOrderAddress ($cart, $method) { @@ -323,6 +370,34 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { continue; if (!empty($filter_conditions['subcategories']) && count(array_intersect($subcategories, $prodcategories))==0) continue; + + if (!empty($filter_conditions['vendors'])) { + // Collect all vendors (ids and slug/login_name - PLUGIN-specific!) + // for the current product. If any of them is in the vendor conditions + // list, this product should not be filtered out! + $vnd_props = array(); + + // THIRD-PARTY SUPPORT + // "WC Vendors" support (vendors stored as post author) + if (class_exists("WC_Vendors")) { + $vendor = $p['data']->post->post_author; + $vnd = get_user_by('id', $vendor); // Get user name by user id + $vnd_props[] = $vendor; + $vnd_props[] = $vnd->user_login; + } + + // "WooThemes Vendor Products" support (vendors stored in its own taxonomy) + if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) { + foreach (get_product_vendors($p['data']->id) as $vendor) { + $vnd_props[] = $vendor->slug; + } + } + // END THIRD-PARTY SUPPORT + + // Check if any of the vendor properties is matched by the conditions; If not => skip product + if (count(array_intersect($vnd_props, $filter_conditions['vendors']))==0) + continue; + } $result[] = $p; } return $result; diff --git a/readme.txt b/readme.txt index e50625a6bf65a238f4c1c4facb66e23e68bc78b5..8fe8bdddbdc0779d7deee8c07958c606f58b008c 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: opentools Tags: WooCommerce, Shipment, Shipping, Rules shipping Requires at least: 4.0 -Tested up to: 4.4.1 -Stable tag: 1.1.1 +Tested up to: 4.4.2 +Stable tag: 1.2 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl.html @@ -69,6 +69,9 @@ Please see our support forum at http://open-tools.net/forum/. It might also be a == Changelog == += 1.2 = +* Add support for "WC Vendors" and for "WooThemes Product Vendors" (new variable "Vendors", new function "evaluate_for_vendors") + = 1.1.1 = * Fix for PHP 5.3 * Fix for evaluate_for_XXX functions (advanced version) diff --git a/releases/opentools-woocommerce-advanced-shipping-by-rules_v1.2.zip b/releases/opentools-woocommerce-advanced-shipping-by-rules_v1.2.zip new file mode 100644 index 0000000000000000000000000000000000000000..f423061785cdab081d1ad2f16b24e5e410a1c71d Binary files /dev/null and b/releases/opentools-woocommerce-advanced-shipping-by-rules_v1.2.zip differ diff --git a/releases/opentools-woocommerce-shipping-by-rules_v1.2.zip b/releases/opentools-woocommerce-shipping-by-rules_v1.2.zip new file mode 100644 index 0000000000000000000000000000000000000000..7f3521fbd18711edca7c65e64d7ad11face9ffa7 Binary files /dev/null and b/releases/opentools-woocommerce-shipping-by-rules_v1.2.zip differ diff --git a/woocommerce-advanced-shipping-by-rules.php b/woocommerce-advanced-shipping-by-rules.php index ec9c55b28d82c7a014f69dce7aff312b3d9e090a..db19ad1eb39ba352daf5c21bdda3ce84b680855c 100644 --- a/woocommerce-advanced-shipping-by-rules.php +++ b/woocommerce-advanced-shipping-by-rules.php @@ -3,14 +3,14 @@ * Plugin Name: WooCommerce Advanced Shipping By Rules * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html * Description: Define Shipping cost by very general and flexible (text-based) rules. The advanced version also provides mathematical expressions and functions - * Version: 1.1.2 + * Version: 1.2 * Author: Open Tools, Reinhold Kainhofer * Author URI: http://open-tools.net * Text Domain: woocommerce-advanced-shipping-by-rules * Domain Path: woocommerce-shipping-by-rules * License: GPL2+ * WC requires at least: 2.2 - * WC tested up to: 2.4 + * WC tested up to: 2.5 * Copyright (C) 2015 Reinhold Kainhofer @@ -66,7 +66,6 @@ function otsr_addAccessCheckArg($downloadurl) { * Main Shipping by Rules class, add filters and handling all other files. * * @class WooCommerce_Shipping_By_Rules_Advanced - * @version 1.1.2 * @author Reinhold Kainhofer */ class WooCommerce_Shipping_By_Rules_Advanced { @@ -76,7 +75,7 @@ class WooCommerce_Shipping_By_Rules_Advanced { * @since 1.0.0 * @var string $version Plugin version number. */ - public $version = '1.1.2'; + public $version = '1.2'; /** diff --git a/woocommerce-shipping-by-rules.php b/woocommerce-shipping-by-rules.php index baefcd5210fbac759842adcd3bb1978a270b7acb..84787834976c6065558ea4d0922b6228ccb2e26d 100644 --- a/woocommerce-shipping-by-rules.php +++ b/woocommerce-shipping-by-rules.php @@ -3,14 +3,14 @@ * Plugin Name: WooCommerce Shipping By Rules * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html * Description: Define Shipping cost by very general and flexible (text-based) rules. - * Version: 1.1.2 + * Version: 1.2 * Author: Open Tools, Reinhold Kainhofer * Author URI: http://open-tools.net * Text Domain: woocommerce-shipping-by-rules * Domain Path: * License: GPL2+ * WC requires at least: 2.2 - * WC tested up to: 2.4 + * WC tested up to: 2.5 * Copyright (C) 2015 Reinhold Kainhofer @@ -39,7 +39,6 @@ * Main Shipping by Rules class, add filters and handling all other files. * * @class WooCommerce_Shipping_By_Rules - * @version 1.1.2 * @author Reinhold Kainhofer */ class WooCommerce_Shipping_By_Rules { @@ -49,7 +48,7 @@ class WooCommerce_Shipping_By_Rules { * @since 1.0.0 * @var string $version Plugin version number. */ - public $version = '1.1.2'; + public $version = '1.2'; /**