Skip to content
Snippets Groups Projects
Commit 69ecd9d6 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

V1.2: Support for third-party vendor plugins

parent a485d27a
Branches
Tags V1.2
No related merge requests found
BASE=shipping-by-rules
PLATTFORM=woocommerce
VENDOR=opentools
VERSION=1.1.2
VERSION=1.2
DIR = $(shell pwd)
SVNDIR=wordpress-plugin-svn
......
......@@ -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;
......
......@@ -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)
......
File added
File added
......@@ -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';
/**
......
......@@ -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';
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment