Changeset 1370301
- Timestamp:
- 03/13/2016 10:05:01 PM (10 years ago)
- Location:
- shipping-by-rules-for-woocommerce
- Files:
-
- 5 edited
- 22 copied
-
tags/1.2 (copied) (copied from shipping-by-rules-for-woocommerce/trunk)
-
tags/1.2.1 (copied) (copied from shipping-by-rules-for-woocommerce/trunk)
-
tags/1.2.1/LICENSE.txt (copied) (copied from shipping-by-rules-for-woocommerce/trunk/LICENSE.txt)
-
tags/1.2.1/assets (copied) (copied from shipping-by-rules-for-woocommerce/trunk/assets)
-
tags/1.2.1/includes (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes)
-
tags/1.2.1/includes/rules-shipping-post-type.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules-shipping-post-type.php)
-
tags/1.2.1/includes/rules_shipping_framework_woocommerce.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce.php) (4 diffs)
-
tags/1.2.1/includes/rules_shipping_framework_woocommerce_advanced.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce_advanced.php) (1 diff)
-
tags/1.2.1/library (copied) (copied from shipping-by-rules-for-woocommerce/trunk/library)
-
tags/1.2.1/library/rules_shipping_framework.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/library/rules_shipping_framework.php) (11 diffs)
-
tags/1.2.1/readme.txt (copied) (copied from shipping-by-rules-for-woocommerce/trunk/readme.txt) (2 diffs)
-
tags/1.2.1/woocommerce-shipping-by-rules.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/woocommerce-shipping-by-rules.php) (4 diffs)
-
tags/1.2/LICENSE.txt (copied) (copied from shipping-by-rules-for-woocommerce/trunk/LICENSE.txt)
-
tags/1.2/assets (copied) (copied from shipping-by-rules-for-woocommerce/trunk/assets)
-
tags/1.2/includes (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes)
-
tags/1.2/includes/rules-shipping-post-type.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules-shipping-post-type.php)
-
tags/1.2/includes/rules_shipping_framework_woocommerce.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce.php) (4 diffs)
-
tags/1.2/includes/rules_shipping_framework_woocommerce_advanced.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce_advanced.php) (1 diff)
-
tags/1.2/library (copied) (copied from shipping-by-rules-for-woocommerce/trunk/library)
-
tags/1.2/library/rules_shipping_framework.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/library/rules_shipping_framework.php) (7 diffs)
-
tags/1.2/readme.txt (copied) (copied from shipping-by-rules-for-woocommerce/trunk/readme.txt) (2 diffs)
-
tags/1.2/woocommerce-shipping-by-rules.php (copied) (copied from shipping-by-rules-for-woocommerce/trunk/woocommerce-shipping-by-rules.php) (4 diffs)
-
trunk/includes/rules_shipping_framework_woocommerce.php (modified) (4 diffs)
-
trunk/includes/rules_shipping_framework_woocommerce_advanced.php (modified) (1 diff)
-
trunk/library/rules_shipping_framework.php (modified) (11 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/woocommerce-shipping-by-rules.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shipping-by-rules-for-woocommerce/tags/1.2.1/includes/rules_shipping_framework_woocommerce.php
r1339835 r1370301 23 23 "products" => 'products', 24 24 "skus" => 'products', 25 "vendors" => 'vendors', 25 26 )); 26 27 } … … 210 211 $tags = array_unique($tags); 211 212 $shipping_classes = array_unique($shipping_classes); 212 213 return array ( 213 214 215 $data = array ( 214 216 'skus' => $skus, 215 217 'categories' => $categories, … … 217 219 'shippingclasses' => $shipping_classes, 218 220 ); 221 222 // THIRD-PARTY SUPPORT 223 224 // "WC Vendors" support (vendors stored as post author) 225 if (class_exists("WC_Vendors")) { 226 $vendorids = array(); 227 foreach ($products as $product) { 228 $vendorids[] = $product['data']->post->post_author; 229 } 230 $data['vendorids'] = array_unique($vendorids); 231 232 $vendors = array(); // Requires "WC Vendors" or "WooThemes Product Vendors" plugin 233 $vendornames = array(); 234 foreach ($data['vendorids'] as $v) { 235 $vnd = get_user_by('id', $v); // Get user name by user id 236 $vendornames[] = $vnd->display_name; 237 $vendors[] = $vnd->user_login; 238 } 239 $data['vendornames'] = array_unique($vendornames); 240 $data['vendors'] = array_unique($vendors); 241 } 242 243 // "WooThemes Vendor Products" support (vendors stored in its own taxonomy) 244 if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) { 245 $vendors = array(); 246 $vendornames = array(); 247 $vendorids = array(); 248 // The plugin provides its own function to retrieve the vendor for a product 249 foreach ($products as $product) { 250 foreach (get_product_vendors($product['data']->id) as $vendor) { 251 // $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>"); 252 $vendors[] = $vendor->slug; 253 $vendornames[] = $vendor->title; 254 $vendorids[] = $vendor->ID; 255 } 256 } 257 $data['vendors'] = array_unique($vendors); 258 $data['vendornames'] = array_unique($vendornames); 259 $data['vendorids'] = array_unique($vendorids); 260 } 261 262 // "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy) 263 if (function_exists("yith_get_vendor")) { 264 $vendors = array(); 265 $vendornames = array(); 266 $vendorids = array(); 267 // The plugin provides its own function to retrieve the vendor for a product 268 foreach ($products as $product) { 269 $vendor = yith_get_vendor($product['data']->id, 'product'); 270 // $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>"); 271 if ($vendor->is_valid()) { 272 $vendors[] = $vendor->slug; 273 $vendornames[] = $vendor->name; 274 $vendorids[] = $vendor->term_id; 275 } 276 } 277 $data['vendors'] = array_unique($vendors); 278 $data['vendornames'] = array_unique($vendornames); 279 $data['vendorids'] = array_unique($vendorids); 280 } 281 282 283 // END THIRD-PARTY SUPPORT 284 285 286 return $data; 219 287 } 220 288 … … 324 392 if (!empty($filter_conditions['subcategories']) && count(array_intersect($subcategories, $prodcategories))==0) 325 393 continue; 394 395 if (!empty($filter_conditions['vendors'])) { 396 // Collect all vendors (ids and slug/login_name - PLUGIN-specific!) 397 // for the current product. If any of them is in the vendor conditions 398 // list, this product should not be filtered out! 399 $vnd_props = array(); 400 401 // THIRD-PARTY SUPPORT 402 // "WC Vendors" support (vendors stored as post author) 403 if (class_exists("WC_Vendors")) { 404 $vendor = $p['data']->post->post_author; 405 $vnd = get_user_by('id', $vendor); // Get user name by user id 406 $vnd_props[] = $vendor; 407 $vnd_props[] = $vnd->user_login; 408 } 409 410 // "WooThemes Vendor Products" support (vendors stored in its own taxonomy) 411 if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) { 412 foreach (get_product_vendors($p['data']->id) as $vendor) { 413 $vnd_props[] = $vendor->slug; 414 } 415 } 416 417 // "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy) 418 if (function_exists("yith_get_vendor")) { 419 $vendor = yith_get_vendor($p['data']->id, 'product'); 420 if ($vendor->is_valid()) { 421 $vnd_props[] = $vendor->slug; 422 } 423 } 424 425 // END THIRD-PARTY SUPPORT 426 427 // Check if any of the vendor properties is matched by the conditions; If not => skip product 428 if (count(array_intersect($vnd_props, $filter_conditions['vendors']))==0) 429 continue; 430 } 326 431 $result[] = $p; 327 432 } -
shipping-by-rules-for-woocommerce/tags/1.2.1/includes/rules_shipping_framework_woocommerce_advanced.php
r1338825 r1370301 30 30 protected function getOrderAddress ($cart, $method) { 31 31 $data = parent::getOrderAddress($cart, $method); 32 $address = $cart['destination']; 32 33 $zip = isset($address['postcode'])?trim($address['postcode']):''; 33 34 if (isset($zip) && $zip!='') { -
shipping-by-rules-for-woocommerce/tags/1.2.1/library/rules_shipping_framework.php
r1338825 r1370301 52 52 class RulesShippingFramework { 53 53 static $_version = "0.1"; 54 protected $ _callbacks = array();54 protected $callbacks = array(); 55 55 // Store the parsed and possibly evaluated rules for each method (method ID is used as key) 56 56 protected $rules = array(); … … 168 168 } 169 169 170 function getCustomFunctionDefinitions() { 171 return $this->custom_functions; 172 } 173 170 174 /** @tag system-specific 171 175 * @function printWarning() … … 204 208 public function setup() { 205 209 $custfuncdefs = $this->getCustomFunctions(); 206 // Loop through the return values of all plugins: 207 foreach ($custfuncdefs as $custfuncs) { 208 if (empty($custfuncs)) 209 continue; 210 if (!is_array($custfuncs)) { 211 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY'); 212 } 213 // Now loop through all custom function definitions of this plugin 214 // If a function was registered before, print a warning and use the first definition 215 foreach ($custfuncs as $fname => $func) { 216 if (isset($this->custom_functions[$fname])) { 217 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname); 218 } else { 219 $this->debug("Defining custom function $fname"); 220 $this->custom_functions[strtolower($fname)] = $func; 221 } 210 // Now loop through all custom function definitions of this plugin 211 // If a function was registered before, print a warning and use the first definition 212 foreach ($custfuncdefs as $fname => $func) { 213 if (isset($this->custom_functions[$fname]) && $this->custom_functions[$fname]!=$custfuncs[$fname]) { 214 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname); 215 } else { 216 $this->debug("Defining custom function $fname"); 217 $this->custom_functions[strtolower($fname)] = $func; 222 218 } 223 219 } … … 288 284 } 289 285 286 protected function getDebugVariables ($cart, $products, $method) { 287 288 return array( 289 'debug_cart'=> print_r($cart,1), 290 'debug_products' => print_r($products, 1), 291 ); 292 } 293 290 294 /** 291 295 * Extract information about non-numerical zip codes (UK and Canada) from the postal code 292 296 */ 293 p rotectedfunction getAddressZIP ($zip) {297 public function getAddressZIP ($zip) { 294 298 $values = array(); 295 299 … … 331 335 */ 332 336 protected function addCustomCartValues ($cart, $products, $method, &$values) { 337 // Pass all args through to the callback, if it exists 333 338 if (isset($this->callbacks['addCustomCartValues'])) { 334 return $this->callbacks['addCustomCartValues']($cart, $products, $method, $values); 335 } 339 return call_user_func_array($this->callbacks['addCustomCartValues'], array($cart, $products, $method, &$values)/*func_get_args()*/); 340 } 341 return $values; 336 342 } 337 343 protected function addPluginCartValues($cart, $products, $method, &$values) { 344 return $values; 338 345 } 339 346 … … 350 357 // Add Total/Min/Max weight and dimension variables: 351 358 $this->getOrderWeights ($cart, $products, $method), 352 $this->getOrderDimensions ($cart, $products, $method) 359 $this->getOrderDimensions ($cart, $products, $method), 360 $this->getDebugVariables ($cart, $products, $method) 353 361 ); 354 362 // Let child classes update the $cartvals array, or add new variables … … 531 539 protected function createMethodRule ($r, $countries, $ruleinfo) { 532 540 if (isset($this->callbacks['initRule'])) { 533 return $this->callbacks['initRule']($this, $r, $countries, $ruleinfo); 541 return call_user_func_array($this->callbacks['initRule'], 542 array($this, $r, $countries, $ruleinfo)); 534 543 } else { 535 544 return new ShippingRule($this, $r, $countries, $ruleinfo); … … 550 559 foreach ($rules1 as $r) { 551 560 // Ignore empty lines 552 if (empty($r) ) continue;561 if (empty($r) || trim($r)=='') continue; 553 562 $result[] = $this->createMethodRule ($r, $countries, $ruleinfo); 554 563 } … … 636 645 /* Both versions create an expression tree, which can be easily evaluated in evaluateTerm */ 637 646 $rulepart = trim($rulepart); 638 if ( empty($rulepart)) return;647 if (!isset($rulepart) || $rulepart==='') return; 639 648 640 649 … … 823 832 // Check if we have a custom function definition and use that if so. 824 833 // This is done first to allow plugins to override even built-in functions! 825 if (isset($this->plugin->custom_functions[$func])) { 834 $customfunctions = $this->framework->getCustomFunctionDefinitions(); 835 if (isset($customfunctions[$func])) { 826 836 $this->framework->debug("Evaluating custom function $function, defined by a plugin"); 827 return call_user_func _array($this->plugin->custom_functions[$func], $args, $this);837 return call_user_func($customfunctions[$func], $args, $this); 828 838 } 829 839 … … 907 917 } elseif ($varname=='values') { 908 918 return $vals; 909 } elseif ($varname=='values_debug') { 910 return print_r($vals,1); 919 } elseif ($varname=='values_debug' || $varname='debug_values') { 920 $tmpvals = $vals; 921 unset($tmpvals['debug_cart']); 922 unset($tmpvals['debug_products']); 923 return print_r($tmpvals,1); 911 924 } else { 912 925 $this->framework->warning('OTSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE', $expr, $this->rulestring); -
shipping-by-rules-for-woocommerce/tags/1.2.1/readme.txt
r1338829 r1370301 3 3 Tags: WooCommerce, Shipment, Shipping, Rules shipping 4 4 Requires at least: 4.0 5 Tested up to: 4.4. 16 Stable tag: 1. 1.15 Tested up to: 4.4.2 6 Stable tag: 1.2.1 7 7 License: GPLv3 or later 8 8 License URI: http://www.gnu.org/licenses/gpl.html … … 70 70 == Changelog == 71 71 72 = 1.2.1 = 73 * Fix for warning when a rule contained only spaces 74 75 = 1.2 = 76 * Add support for "WC Vendors" and for "WooThemes Product Vendors" (new variable "Vendors", new function "evaluate_for_vendors") 77 72 78 = 1.1.1 = 73 79 * Fix for PHP 5.3 -
shipping-by-rules-for-woocommerce/tags/1.2.1/woocommerce-shipping-by-rules.php
r1338825 r1370301 4 4 * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html 5 5 * Description: Define Shipping cost by very general and flexible (text-based) rules. 6 * Version: 1. 1.16 * Version: 1.2.1 7 7 * Author: Open Tools, Reinhold Kainhofer 8 8 * Author URI: http://open-tools.net … … 11 11 * License: GPL2+ 12 12 * WC requires at least: 2.2 13 * WC tested up to: 2. 413 * WC tested up to: 2.5 14 14 15 15 … … 40 40 * 41 41 * @class WooCommerce_Shipping_By_Rules 42 * @version 1.1.143 42 * @author Reinhold Kainhofer 44 43 */ … … 50 49 * @var string $version Plugin version number. 51 50 */ 52 public $version = '1. 1.1';51 public $version = '1.2.1'; 53 52 54 53 -
shipping-by-rules-for-woocommerce/tags/1.2/includes/rules_shipping_framework_woocommerce.php
r1339835 r1370301 23 23 "products" => 'products', 24 24 "skus" => 'products', 25 "vendors" => 'vendors', 25 26 )); 26 27 } … … 210 211 $tags = array_unique($tags); 211 212 $shipping_classes = array_unique($shipping_classes); 212 213 return array ( 213 214 215 $data = array ( 214 216 'skus' => $skus, 215 217 'categories' => $categories, … … 217 219 'shippingclasses' => $shipping_classes, 218 220 ); 221 222 // THIRD-PARTY SUPPORT 223 224 // "WC Vendors" support (vendors stored as post author) 225 if (class_exists("WC_Vendors")) { 226 $vendorids = array(); 227 foreach ($products as $product) { 228 $vendorids[] = $product['data']->post->post_author; 229 } 230 $data['vendorids'] = array_unique($vendorids); 231 232 $vendors = array(); // Requires "WC Vendors" or "WooThemes Product Vendors" plugin 233 $vendornames = array(); 234 foreach ($data['vendorids'] as $v) { 235 $vnd = get_user_by('id', $v); // Get user name by user id 236 $vendornames[] = $vnd->display_name; 237 $vendors[] = $vnd->user_login; 238 } 239 $data['vendornames'] = array_unique($vendornames); 240 $data['vendors'] = array_unique($vendors); 241 } 242 243 // "WooThemes Vendor Products" support (vendors stored in its own taxonomy) 244 if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) { 245 $vendors = array(); 246 $vendornames = array(); 247 $vendorids = array(); 248 // The plugin provides its own function to retrieve the vendor for a product 249 foreach ($products as $product) { 250 foreach (get_product_vendors($product['data']->id) as $vendor) { 251 // $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>"); 252 $vendors[] = $vendor->slug; 253 $vendornames[] = $vendor->title; 254 $vendorids[] = $vendor->ID; 255 } 256 } 257 $data['vendors'] = array_unique($vendors); 258 $data['vendornames'] = array_unique($vendornames); 259 $data['vendorids'] = array_unique($vendorids); 260 } 261 262 // END THIRD-PARTY SUPPORT 263 264 265 return $data; 219 266 } 220 267 … … 324 371 if (!empty($filter_conditions['subcategories']) && count(array_intersect($subcategories, $prodcategories))==0) 325 372 continue; 373 374 if (!empty($filter_conditions['vendors'])) { 375 // Collect all vendors (ids and slug/login_name - PLUGIN-specific!) 376 // for the current product. If any of them is in the vendor conditions 377 // list, this product should not be filtered out! 378 $vnd_props = array(); 379 380 // THIRD-PARTY SUPPORT 381 // "WC Vendors" support (vendors stored as post author) 382 if (class_exists("WC_Vendors")) { 383 $vendor = $p['data']->post->post_author; 384 $vnd = get_user_by('id', $vendor); // Get user name by user id 385 $vnd_props[] = $vendor; 386 $vnd_props[] = $vnd->user_login; 387 } 388 389 // "WooThemes Vendor Products" support (vendors stored in its own taxonomy) 390 if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) { 391 foreach (get_product_vendors($p['data']->id) as $vendor) { 392 $vnd_props[] = $vendor->slug; 393 } 394 } 395 // END THIRD-PARTY SUPPORT 396 397 // Check if any of the vendor properties is matched by the conditions; If not => skip product 398 if (count(array_intersect($vnd_props, $filter_conditions['vendors']))==0) 399 continue; 400 } 326 401 $result[] = $p; 327 402 } -
shipping-by-rules-for-woocommerce/tags/1.2/includes/rules_shipping_framework_woocommerce_advanced.php
r1338825 r1370301 30 30 protected function getOrderAddress ($cart, $method) { 31 31 $data = parent::getOrderAddress($cart, $method); 32 $address = $cart['destination']; 32 33 $zip = isset($address['postcode'])?trim($address['postcode']):''; 33 34 if (isset($zip) && $zip!='') { -
shipping-by-rules-for-woocommerce/tags/1.2/library/rules_shipping_framework.php
r1338825 r1370301 168 168 } 169 169 170 function getCustomFunctionDefinitions() { 171 return $this->custom_functions; 172 } 173 170 174 /** @tag system-specific 171 175 * @function printWarning() … … 204 208 public function setup() { 205 209 $custfuncdefs = $this->getCustomFunctions(); 206 // Loop through the return values of all plugins: 207 foreach ($custfuncdefs as $custfuncs) { 208 if (empty($custfuncs)) 209 continue; 210 if (!is_array($custfuncs)) { 211 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY'); 212 } 213 // Now loop through all custom function definitions of this plugin 214 // If a function was registered before, print a warning and use the first definition 215 foreach ($custfuncs as $fname => $func) { 216 if (isset($this->custom_functions[$fname])) { 217 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname); 218 } else { 219 $this->debug("Defining custom function $fname"); 220 $this->custom_functions[strtolower($fname)] = $func; 221 } 210 // Now loop through all custom function definitions of this plugin 211 // If a function was registered before, print a warning and use the first definition 212 foreach ($custfuncdefs as $fname => $func) { 213 if (isset($this->custom_functions[$fname]) && $this->custom_functions[$fname]!=$custfuncs[$fname]) { 214 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname); 215 } else { 216 $this->debug("Defining custom function $fname"); 217 $this->custom_functions[strtolower($fname)] = $func; 222 218 } 223 219 } … … 288 284 } 289 285 286 protected function getDebugVariables ($cart, $products, $method) { 287 288 return array( 289 'debug_cart'=> print_r($cart,1), 290 'debug_products' => print_r($products, 1), 291 ); 292 } 293 290 294 /** 291 295 * Extract information about non-numerical zip codes (UK and Canada) from the postal code … … 350 354 // Add Total/Min/Max weight and dimension variables: 351 355 $this->getOrderWeights ($cart, $products, $method), 352 $this->getOrderDimensions ($cart, $products, $method) 356 $this->getOrderDimensions ($cart, $products, $method), 357 $this->getDebugVariables ($cart, $products, $method) 353 358 ); 354 359 // Let child classes update the $cartvals array, or add new variables … … 636 641 /* Both versions create an expression tree, which can be easily evaluated in evaluateTerm */ 637 642 $rulepart = trim($rulepart); 638 if ( empty($rulepart)) return;643 if (!isset($rulepart) || $rulepart==='') return; 639 644 640 645 … … 823 828 // Check if we have a custom function definition and use that if so. 824 829 // This is done first to allow plugins to override even built-in functions! 825 if (isset($this->plugin->custom_functions[$func])) { 830 $customfunctions = $this->framework->getCustomFunctionDefinitions(); 831 if (isset($customfunctions[$func])) { 826 832 $this->framework->debug("Evaluating custom function $function, defined by a plugin"); 827 return call_user_func _array($this->plugin->custom_functions[$func], $args, $this);833 return call_user_func($customfunctions[$func], $args, $this); 828 834 } 829 835 … … 907 913 } elseif ($varname=='values') { 908 914 return $vals; 909 } elseif ($varname=='values_debug') { 910 return print_r($vals,1); 915 } elseif ($varname=='values_debug' || $varname='debug_values') { 916 $tmpvals = $vals; 917 unset($tmpvals['debug_cart']); 918 unset($tmpvals['debug_products']); 919 return print_r($tmpvals,1); 911 920 } else { 912 921 $this->framework->warning('OTSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE', $expr, $this->rulestring); -
shipping-by-rules-for-woocommerce/tags/1.2/readme.txt
r1338829 r1370301 3 3 Tags: WooCommerce, Shipment, Shipping, Rules shipping 4 4 Requires at least: 4.0 5 Tested up to: 4.4. 16 Stable tag: 1. 1.15 Tested up to: 4.4.2 6 Stable tag: 1.2 7 7 License: GPLv3 or later 8 8 License URI: http://www.gnu.org/licenses/gpl.html … … 70 70 == Changelog == 71 71 72 = 1.2 = 73 * Add support for "WC Vendors" and for "WooThemes Product Vendors" (new variable "Vendors", new function "evaluate_for_vendors") 74 72 75 = 1.1.1 = 73 76 * Fix for PHP 5.3 -
shipping-by-rules-for-woocommerce/tags/1.2/woocommerce-shipping-by-rules.php
r1338825 r1370301 4 4 * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html 5 5 * Description: Define Shipping cost by very general and flexible (text-based) rules. 6 * Version: 1. 1.16 * Version: 1.2 7 7 * Author: Open Tools, Reinhold Kainhofer 8 8 * Author URI: http://open-tools.net … … 11 11 * License: GPL2+ 12 12 * WC requires at least: 2.2 13 * WC tested up to: 2. 413 * WC tested up to: 2.5 14 14 15 15 … … 40 40 * 41 41 * @class WooCommerce_Shipping_By_Rules 42 * @version 1.1.143 42 * @author Reinhold Kainhofer 44 43 */ … … 50 49 * @var string $version Plugin version number. 51 50 */ 52 public $version = '1. 1.1';51 public $version = '1.2'; 53 52 54 53 -
shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce.php
r1339835 r1370301 23 23 "products" => 'products', 24 24 "skus" => 'products', 25 "vendors" => 'vendors', 25 26 )); 26 27 } … … 210 211 $tags = array_unique($tags); 211 212 $shipping_classes = array_unique($shipping_classes); 212 213 return array ( 213 214 215 $data = array ( 214 216 'skus' => $skus, 215 217 'categories' => $categories, … … 217 219 'shippingclasses' => $shipping_classes, 218 220 ); 221 222 // THIRD-PARTY SUPPORT 223 224 // "WC Vendors" support (vendors stored as post author) 225 if (class_exists("WC_Vendors")) { 226 $vendorids = array(); 227 foreach ($products as $product) { 228 $vendorids[] = $product['data']->post->post_author; 229 } 230 $data['vendorids'] = array_unique($vendorids); 231 232 $vendors = array(); // Requires "WC Vendors" or "WooThemes Product Vendors" plugin 233 $vendornames = array(); 234 foreach ($data['vendorids'] as $v) { 235 $vnd = get_user_by('id', $v); // Get user name by user id 236 $vendornames[] = $vnd->display_name; 237 $vendors[] = $vnd->user_login; 238 } 239 $data['vendornames'] = array_unique($vendornames); 240 $data['vendors'] = array_unique($vendors); 241 } 242 243 // "WooThemes Vendor Products" support (vendors stored in its own taxonomy) 244 if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) { 245 $vendors = array(); 246 $vendornames = array(); 247 $vendorids = array(); 248 // The plugin provides its own function to retrieve the vendor for a product 249 foreach ($products as $product) { 250 foreach (get_product_vendors($product['data']->id) as $vendor) { 251 // $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>"); 252 $vendors[] = $vendor->slug; 253 $vendornames[] = $vendor->title; 254 $vendorids[] = $vendor->ID; 255 } 256 } 257 $data['vendors'] = array_unique($vendors); 258 $data['vendornames'] = array_unique($vendornames); 259 $data['vendorids'] = array_unique($vendorids); 260 } 261 262 // "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy) 263 if (function_exists("yith_get_vendor")) { 264 $vendors = array(); 265 $vendornames = array(); 266 $vendorids = array(); 267 // The plugin provides its own function to retrieve the vendor for a product 268 foreach ($products as $product) { 269 $vendor = yith_get_vendor($product['data']->id, 'product'); 270 // $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>"); 271 if ($vendor->is_valid()) { 272 $vendors[] = $vendor->slug; 273 $vendornames[] = $vendor->name; 274 $vendorids[] = $vendor->term_id; 275 } 276 } 277 $data['vendors'] = array_unique($vendors); 278 $data['vendornames'] = array_unique($vendornames); 279 $data['vendorids'] = array_unique($vendorids); 280 } 281 282 283 // END THIRD-PARTY SUPPORT 284 285 286 return $data; 219 287 } 220 288 … … 324 392 if (!empty($filter_conditions['subcategories']) && count(array_intersect($subcategories, $prodcategories))==0) 325 393 continue; 394 395 if (!empty($filter_conditions['vendors'])) { 396 // Collect all vendors (ids and slug/login_name - PLUGIN-specific!) 397 // for the current product. If any of them is in the vendor conditions 398 // list, this product should not be filtered out! 399 $vnd_props = array(); 400 401 // THIRD-PARTY SUPPORT 402 // "WC Vendors" support (vendors stored as post author) 403 if (class_exists("WC_Vendors")) { 404 $vendor = $p['data']->post->post_author; 405 $vnd = get_user_by('id', $vendor); // Get user name by user id 406 $vnd_props[] = $vendor; 407 $vnd_props[] = $vnd->user_login; 408 } 409 410 // "WooThemes Vendor Products" support (vendors stored in its own taxonomy) 411 if (class_exists("WooCommerce_Product_Vendors") && function_exists("get_product_vendors")) { 412 foreach (get_product_vendors($p['data']->id) as $vendor) { 413 $vnd_props[] = $vendor->slug; 414 } 415 } 416 417 // "YITH WooCommerce Multi Vendor" support (vendors stored in its own taxonomy) 418 if (function_exists("yith_get_vendor")) { 419 $vendor = yith_get_vendor($p['data']->id, 'product'); 420 if ($vendor->is_valid()) { 421 $vnd_props[] = $vendor->slug; 422 } 423 } 424 425 // END THIRD-PARTY SUPPORT 426 427 // Check if any of the vendor properties is matched by the conditions; If not => skip product 428 if (count(array_intersect($vnd_props, $filter_conditions['vendors']))==0) 429 continue; 430 } 326 431 $result[] = $p; 327 432 } -
shipping-by-rules-for-woocommerce/trunk/includes/rules_shipping_framework_woocommerce_advanced.php
r1338825 r1370301 30 30 protected function getOrderAddress ($cart, $method) { 31 31 $data = parent::getOrderAddress($cart, $method); 32 $address = $cart['destination']; 32 33 $zip = isset($address['postcode'])?trim($address['postcode']):''; 33 34 if (isset($zip) && $zip!='') { -
shipping-by-rules-for-woocommerce/trunk/library/rules_shipping_framework.php
r1338825 r1370301 52 52 class RulesShippingFramework { 53 53 static $_version = "0.1"; 54 protected $ _callbacks = array();54 protected $callbacks = array(); 55 55 // Store the parsed and possibly evaluated rules for each method (method ID is used as key) 56 56 protected $rules = array(); … … 168 168 } 169 169 170 function getCustomFunctionDefinitions() { 171 return $this->custom_functions; 172 } 173 170 174 /** @tag system-specific 171 175 * @function printWarning() … … 204 208 public function setup() { 205 209 $custfuncdefs = $this->getCustomFunctions(); 206 // Loop through the return values of all plugins: 207 foreach ($custfuncdefs as $custfuncs) { 208 if (empty($custfuncs)) 209 continue; 210 if (!is_array($custfuncs)) { 211 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY'); 212 } 213 // Now loop through all custom function definitions of this plugin 214 // If a function was registered before, print a warning and use the first definition 215 foreach ($custfuncs as $fname => $func) { 216 if (isset($this->custom_functions[$fname])) { 217 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname); 218 } else { 219 $this->debug("Defining custom function $fname"); 220 $this->custom_functions[strtolower($fname)] = $func; 221 } 210 // Now loop through all custom function definitions of this plugin 211 // If a function was registered before, print a warning and use the first definition 212 foreach ($custfuncdefs as $fname => $func) { 213 if (isset($this->custom_functions[$fname]) && $this->custom_functions[$fname]!=$custfuncs[$fname]) { 214 $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname); 215 } else { 216 $this->debug("Defining custom function $fname"); 217 $this->custom_functions[strtolower($fname)] = $func; 222 218 } 223 219 } … … 288 284 } 289 285 286 protected function getDebugVariables ($cart, $products, $method) { 287 288 return array( 289 'debug_cart'=> print_r($cart,1), 290 'debug_products' => print_r($products, 1), 291 ); 292 } 293 290 294 /** 291 295 * Extract information about non-numerical zip codes (UK and Canada) from the postal code 292 296 */ 293 p rotectedfunction getAddressZIP ($zip) {297 public function getAddressZIP ($zip) { 294 298 $values = array(); 295 299 … … 331 335 */ 332 336 protected function addCustomCartValues ($cart, $products, $method, &$values) { 337 // Pass all args through to the callback, if it exists 333 338 if (isset($this->callbacks['addCustomCartValues'])) { 334 return $this->callbacks['addCustomCartValues']($cart, $products, $method, $values); 335 } 339 return call_user_func_array($this->callbacks['addCustomCartValues'], array($cart, $products, $method, &$values)/*func_get_args()*/); 340 } 341 return $values; 336 342 } 337 343 protected function addPluginCartValues($cart, $products, $method, &$values) { 344 return $values; 338 345 } 339 346 … … 350 357 // Add Total/Min/Max weight and dimension variables: 351 358 $this->getOrderWeights ($cart, $products, $method), 352 $this->getOrderDimensions ($cart, $products, $method) 359 $this->getOrderDimensions ($cart, $products, $method), 360 $this->getDebugVariables ($cart, $products, $method) 353 361 ); 354 362 // Let child classes update the $cartvals array, or add new variables … … 531 539 protected function createMethodRule ($r, $countries, $ruleinfo) { 532 540 if (isset($this->callbacks['initRule'])) { 533 return $this->callbacks['initRule']($this, $r, $countries, $ruleinfo); 541 return call_user_func_array($this->callbacks['initRule'], 542 array($this, $r, $countries, $ruleinfo)); 534 543 } else { 535 544 return new ShippingRule($this, $r, $countries, $ruleinfo); … … 550 559 foreach ($rules1 as $r) { 551 560 // Ignore empty lines 552 if (empty($r) ) continue;561 if (empty($r) || trim($r)=='') continue; 553 562 $result[] = $this->createMethodRule ($r, $countries, $ruleinfo); 554 563 } … … 636 645 /* Both versions create an expression tree, which can be easily evaluated in evaluateTerm */ 637 646 $rulepart = trim($rulepart); 638 if ( empty($rulepart)) return;647 if (!isset($rulepart) || $rulepart==='') return; 639 648 640 649 … … 823 832 // Check if we have a custom function definition and use that if so. 824 833 // This is done first to allow plugins to override even built-in functions! 825 if (isset($this->plugin->custom_functions[$func])) { 834 $customfunctions = $this->framework->getCustomFunctionDefinitions(); 835 if (isset($customfunctions[$func])) { 826 836 $this->framework->debug("Evaluating custom function $function, defined by a plugin"); 827 return call_user_func _array($this->plugin->custom_functions[$func], $args, $this);837 return call_user_func($customfunctions[$func], $args, $this); 828 838 } 829 839 … … 907 917 } elseif ($varname=='values') { 908 918 return $vals; 909 } elseif ($varname=='values_debug') { 910 return print_r($vals,1); 919 } elseif ($varname=='values_debug' || $varname='debug_values') { 920 $tmpvals = $vals; 921 unset($tmpvals['debug_cart']); 922 unset($tmpvals['debug_products']); 923 return print_r($tmpvals,1); 911 924 } else { 912 925 $this->framework->warning('OTSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE', $expr, $this->rulestring); -
shipping-by-rules-for-woocommerce/trunk/readme.txt
r1338829 r1370301 3 3 Tags: WooCommerce, Shipment, Shipping, Rules shipping 4 4 Requires at least: 4.0 5 Tested up to: 4.4. 16 Stable tag: 1. 1.15 Tested up to: 4.4.2 6 Stable tag: 1.2.1 7 7 License: GPLv3 or later 8 8 License URI: http://www.gnu.org/licenses/gpl.html … … 70 70 == Changelog == 71 71 72 = 1.2.1 = 73 * Fix for warning when a rule contained only spaces 74 75 = 1.2 = 76 * Add support for "WC Vendors" and for "WooThemes Product Vendors" (new variable "Vendors", new function "evaluate_for_vendors") 77 72 78 = 1.1.1 = 73 79 * Fix for PHP 5.3 -
shipping-by-rules-for-woocommerce/trunk/woocommerce-shipping-by-rules.php
r1338825 r1370301 4 4 * Plugin URI: http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html 5 5 * Description: Define Shipping cost by very general and flexible (text-based) rules. 6 * Version: 1. 1.16 * Version: 1.2.1 7 7 * Author: Open Tools, Reinhold Kainhofer 8 8 * Author URI: http://open-tools.net … … 11 11 * License: GPL2+ 12 12 * WC requires at least: 2.2 13 * WC tested up to: 2. 413 * WC tested up to: 2.5 14 14 15 15 … … 40 40 * 41 41 * @class WooCommerce_Shipping_By_Rules 42 * @version 1.1.143 42 * @author Reinhold Kainhofer 44 43 */ … … 50 49 * @var string $version Plugin version number. 51 50 */ 52 public $version = '1. 1.1';51 public $version = '1.2.1'; 53 52 54 53
Note: See TracChangeset
for help on using the changeset viewer.