Changeset 2282505
- Timestamp:
- 04/13/2020 03:47:58 PM (6 years ago)
- Location:
- deliveryplus-by-invisible-dragon
- Files:
-
- 28 added
- 14 edited
- 1 copied
-
tags/1.0 (copied) (copied from deliveryplus-by-invisible-dragon/trunk)
-
tags/1.0/.phpcs.xml.dist (added)
-
tags/1.0/admin.js (modified) (5 diffs)
-
tags/1.0/bin/install-wp-tests.sh (added)
-
tags/1.0/bin/setup-tests.sh (added)
-
tags/1.0/class.DeliveryPlus_Filter_Category.php (modified) (1 diff)
-
tags/1.0/class.DeliveryPlus_Filter_Number.php (added)
-
tags/1.0/class.DeliveryPlus_Filter_SubTotal.php (added)
-
tags/1.0/class.DeliveryPlus_Filter_Weight.php (added)
-
tags/1.0/class.DeliveryPlus_Filters.php (modified) (7 diffs)
-
tags/1.0/class.DeliveryPlus_Shipping_Method.php (modified) (4 diffs)
-
tags/1.0/docs (added)
-
tags/1.0/docs/deliveryplus.md (added)
-
tags/1.0/id-delivery.php (modified) (2 diffs)
-
tags/1.0/includes/filters.php (modified) (5 diffs)
-
tags/1.0/phpunit.xml.dist (added)
-
tags/1.0/readme.txt (modified) (3 diffs)
-
tags/1.0/tests (added)
-
tags/1.0/tests/bootstrap.php (added)
-
tags/1.0/tests/test-filter.php (added)
-
tags/1.0/tests/test-replacements.php (added)
-
tags/1.0/tests/test-weight-filter.php (added)
-
trunk/.phpcs.xml.dist (added)
-
trunk/admin.js (modified) (5 diffs)
-
trunk/bin/install-wp-tests.sh (added)
-
trunk/bin/setup-tests.sh (added)
-
trunk/class.DeliveryPlus_Filter_Category.php (modified) (1 diff)
-
trunk/class.DeliveryPlus_Filter_Number.php (added)
-
trunk/class.DeliveryPlus_Filter_SubTotal.php (added)
-
trunk/class.DeliveryPlus_Filter_Weight.php (added)
-
trunk/class.DeliveryPlus_Filters.php (modified) (7 diffs)
-
trunk/class.DeliveryPlus_Shipping_Method.php (modified) (4 diffs)
-
trunk/docs (added)
-
trunk/docs/deliveryplus.md (added)
-
trunk/id-delivery.php (modified) (2 diffs)
-
trunk/includes/filters.php (modified) (5 diffs)
-
trunk/phpunit.xml.dist (added)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/tests (added)
-
trunk/tests/bootstrap.php (added)
-
trunk/tests/test-filter.php (added)
-
trunk/tests/test-replacements.php (added)
-
trunk/tests/test-weight-filter.php (added)
Legend:
- Unmodified
- Added
- Removed
-
deliveryplus-by-invisible-dragon/tags/1.0/admin.js
r2251671 r2282505 8 8 $(".id-filtering").each(function () { 9 9 10 // When category is picked, load next option down 10 11 $(this).on("change", ".id-filter-category", function () { 11 12 var nextDrop = $(".id-filter-condition", $(this).closest("tr")); … … 14 15 nextDrop.html(''); 15 16 for(let key in data) { 16 $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop); 17 var nVal = data[key]; 18 19 $("<option>").attr("value", key).text(nVal['label']).attr("data-type", nVal['type']).appendTo(nextDrop); 17 20 } 18 21 if(nextDrop.attr("data-value")) { 22 // If we need to pre-set, pre-set 19 23 nextDrop.val(nextDrop.attr("data-value")); 20 24 nextDrop.removeAttr("data-value"); 21 25 } 26 // Load default values 22 27 nextDrop.trigger('change'); 23 28 }); 24 29 }); 25 30 31 // When condition type is changed, update dropdown 26 32 $(this).on("change", ".id-filter-condition", function () { 33 // Get the type of the condition value 34 var category = $(".id-filter-category", $(this).closest("tr")).val(); 35 var nextType = $("option:selected", $(this)).attr("data-type"); 36 27 37 var nextDrop = $(".id-filter-value", $(this).closest("tr")); 28 nextDrop.html('<option>...</option>'); 29 var category = $(".id-filter-category", $(this).closest("tr")).val(); 30 $.getJSON(window.ajaxurl + "?action=deliveryplus_get_values&category=" + category +"&condition=" + $(this).val(), function (data) { 31 nextDrop.html(''); 32 for(let key in data) { 33 $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop); 38 var n = $("<div>").addClass("id-filter-value").text("..."); 39 nextDrop.replaceWith(n); 40 nextDrop = n; 41 42 if(nextType == 'pick'){ 43 44 $.getJSON(window.ajaxurl + "?action=deliveryplus_get_values&category=" + category +"&condition=" + $(this).val(), function (data) { 45 var n = $("<select>").addClass("id-filter-value"); 46 nextDrop.replaceWith(n); 47 nextDrop = n; 48 for(let key in data) { 49 $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop); 50 } 51 if(nextDrop.parent().attr("data-value")) { 52 nextDrop.val(nextDrop.parent().attr("data-value")); 53 nextDrop.parent().removeAttr("data-value"); 54 } 55 nextDrop.trigger('change'); 56 }); 57 58 } else if(nextType == 'value'){ 59 60 let n = $("<input>").addClass("id-filter-value input-text").attr("type", "text"); 61 nextDrop.replaceWith(n); 62 nextDrop = n; 63 if(nextDrop.parent().attr("data-value")) { 64 nextDrop.val(nextDrop.parent().attr("data-value")); 65 nextDrop.parent().removeAttr("data-value"); 34 66 } 35 if(nextDrop.attr("data-value")) { 36 nextDrop.val(nextDrop.attr("data-value")); 37 nextDrop.removeAttr("data-value"); 38 } 39 nextDrop.trigger('change'); 40 }); 67 68 }else { 69 nextDrop.text("! " + nextType); 70 } 41 71 }); 42 72 73 // Delete Row 74 $(this).on("click", ".id-remove-row", function(e){ 75 e.preventDefault(); 76 $(this).closest("tr").remove(); 77 }); 78 79 // Delete Block 80 $(this).on("click", ".id-remove-block", function(e){ 81 e.preventDefault(); 82 $(this).closest(".id-filter-set").remove(); 83 }); 84 85 // New Row 43 86 $(this).on("click", ".id-add-new-and", function() { 44 87 newAndCondition($(this).closest("table")); 45 88 }); 46 89 90 // New Block 47 91 $(this).on("click", ".id-add-new-or", function(){ 48 92 newOrCondition(); … … 56 100 $(".id-filter-category", n).val(row['category']); 57 101 $(".id-filter-condition", n).attr("data-value", row['condition']); 58 $(".id-filter-value", n). attr("data-value", row['value']);102 $(".id-filter-value", n).parent().attr("data-value", row['value']); 59 103 } 60 104 … … 75 119 } 76 120 77 let items = JSON.parse($("input", $(".id-filtering").closest('fieldset')).val() || '[]'); 121 // Parse input from saved 122 let items = JSON.parse($("input[type='hidden']", $(".id-filtering").closest('fieldset')).val() || '[]'); 78 123 79 124 if(items.length > 0) { … … 99 144 }); 100 145 101 $("input ", $(".id-filtering").closest('fieldset')).val(JSON.stringify(ret));146 $("input[type='hidden']", $(".id-filtering").closest('fieldset')).val(JSON.stringify(ret)); 102 147 103 148 } 104 149 105 $(this).on("change", "select ", function(){150 $(this).on("change", "select, input[type='text']", function(){ 106 151 renderJSON(); 107 152 }); -
deliveryplus-by-invisible-dragon/tags/1.0/class.DeliveryPlus_Filter_Category.php
r2251671 r2282505 1 1 <?php 2 2 3 class DeliveryPlus_Filter_Category { 3 class DeliveryPlus_Filter_Category extends DeliveryPlus_Filter_Set { 4 5 public static $category = 'Category'; 6 7 public static function category_label(){ return __('Category'); } 4 8 5 9 public static function activate() { 10 parent::activate(); 6 11 add_filter( 'deliveryplus_filter_Category_1', array( static::class, 'at_least_one' ), 10, 3 ); 7 12 add_filter( 'deliveryplus_filter_Category_!', array( static::class, 'none' ), 10, 3 ); 8 13 add_filter( 'deliveryplus_filter_Category_!a', array( static::class, 'not_all' ), 10, 3 ); 9 14 add_filter( 'deliveryplus_filter_Category_a', array( static::class, 'all' ), 10, 3 ); 15 } 16 17 public static function get_conditions($conditions) { 18 $ret['1'] = new DPF_Pick_Value(__('at least one in')); 19 $ret['a'] = new DPF_Pick_Value(__('all must be in')); 20 $ret['!'] = new DPF_Pick_Value(__('none must be in')); 21 $ret['!a'] = new DPF_Pick_Value(__('not all in')); 22 return $ret; 23 } 24 25 public static function get_values($ret, $condition) { 26 $raw = get_categories(array('taxonomy' => 'product_cat', 'hide_empty' => false)); 27 foreach($raw as $cat) { 28 $ret[$cat->term_id] = wp_specialchars_decode( $cat->name ); 29 } 30 return $ret; 10 31 } 11 32 -
deliveryplus-by-invisible-dragon/tags/1.0/class.DeliveryPlus_Filters.php
r2251671 r2282505 1 1 <?php 2 2 3 require_once "class.DeliveryPlus_Filter_Category.php"; 3 /** 4 * This is a standard DeliveryPlus condition, specifying the value for this 5 * condition should be entered into a textbox 6 */ 7 class DPF_Value { 8 9 public $type = 'value'; 10 11 public function __construct($label) { 12 $this->label = $label; 13 } 14 15 public function toJSON() { 16 return array( 17 'type' => $this->type, 18 'label' => $this->label 19 ); 20 } 21 22 } 23 24 /** 25 * This is a variation of a DeliveryPlus conditon, whereby the value 26 * needs to be picked from a dropdown list. 27 */ 28 class DPF_Pick_Value extends DPF_Value { 29 30 public $type = 'pick'; 31 32 } 33 34 abstract class DeliveryPlus_Filter_Set { 35 36 public static $category = 'Unknown'; 37 public static function category_label(){ return __('Unknown'); } 38 39 public static function activate() { 40 41 add_filter( 'deliveryplus_categories', array( static::class, 'add_category' ) ); 42 add_filter( 'deliveryplus_values_' . static::$category, array( static::class, 'get_values' ), 10, 2 ); 43 add_filter( 'deliveryplus_conditions_' . static::$category, array( static::class, 'get_conditions' ) ); 44 45 // Now associate a filter function for each condition 46 $conditions = static::get_conditions(array()); 47 foreach($conditions as $key => $val) { 48 add_filter( 'deliveryplus_filter_' . static::$category . '_' . $key, array( static::class, 'do_' . $key ), 10, 3 ); 49 } 50 51 } 52 53 abstract public static function get_conditions($conditions); 54 55 public static function get_values($ret, $condition){ 56 // TODO by sub-function 57 return $ret; 58 } 59 60 public static function add_category($filters) { 61 $filters[static::$category] = static::category_label(); 62 return $filters; 63 } 64 } 65 4 66 5 67 class DeliveryPlus_Filters { … … 9 71 add_action( 'wp_ajax_deliveryplus_get_values', array( static::class, 'get_values_ajax' ) ); 10 72 73 // Activate default filters 74 require_once "class.DeliveryPlus_Filter_Number.php"; 75 require_once "class.DeliveryPlus_Filter_Weight.php"; 76 require_once "class.DeliveryPlus_Filter_Category.php"; 77 require_once "class.DeliveryPlus_Filter_SubTotal.php"; 78 11 79 DeliveryPlus_Filter_Category::activate(); 80 DeliveryPlus_Filter_SubTotal::activate(); 81 DeliveryPlus_Filter_Weight::activate(); 12 82 } 13 83 … … 26 96 public static function get_categories() { 27 97 28 $categories[] = 'Category'; 29 30 $categories = apply_filters( 'deliveryplus_categories', $categories ); 98 $categories = apply_filters( 'deliveryplus_categories', array() ); 31 99 32 100 return $categories; … … 37 105 38 106 $ret = []; 39 40 if($category == 'Category') { 41 $raw = get_categories(array('taxonomy' => 'product_cat', 'hide_empty' => false)); 42 foreach($raw as $cat) { 43 $ret[$cat->term_id] = wp_specialchars_decode( $cat->name ); 44 } 45 } 46 47 $ret = apply_filters( 'deliveryplus_values_' . $category, $ret ); 107 $ret = apply_filters( 'deliveryplus_values_' . $category, $ret, $condition ); 48 108 49 109 return $ret; … … 64 124 65 125 $ret = []; 66 67 if($category == 'Category') {68 $ret['1'] = 'at least one in';69 $ret['a'] = 'all must be in';70 $ret['!'] = 'none must be in';71 $ret['!a'] = 'not all in';72 }73 74 126 $ret = apply_filters( 'deliveryplus_conditions_' . $category, $ret ); 75 127 … … 84 136 public static function filter_block_package( $block, $package ) { 85 137 138 if(empty($block)) { 139 return true; 140 } 141 86 142 foreach( $block as $rule ) { 87 143 88 144 $filter = 'deliveryplus_filter_' . $rule['category'] . '_' . $rule['condition']; 89 145 if(!apply_filters($filter, false, $package, $rule)) { 90 var_dump($filter);91 146 return false; 92 147 } … … 99 154 100 155 public static function filter_package( $filters, $package ) { 156 157 if(empty($filters)) { 158 return true; 159 } 101 160 102 161 foreach($filters as $block) { -
deliveryplus-by-invisible-dragon/tags/1.0/class.DeliveryPlus_Shipping_Method.php
r2251671 r2282505 31 31 'default' => __( 'DeliveryPlus' ) 32 32 ), 33 'tax_status' => array( 34 'title' => __( 'Tax status', 'woocommerce' ), 35 'type' => 'select', 36 'class' => 'wc-enhanced-select', 37 'default' => 'taxable', 38 'options' => array( 39 'taxable' => __( 'Taxable', 'woocommerce' ), 40 'none' => _x( 'None', 'Tax status', 'woocommerce' ), 41 ), 42 ), 33 43 'rate' => array( 34 44 'title' => __( 'Rate' ), … … 247 257 // Now we can do some area calculations 248 258 if($width && $length){ 249 $total_flat_area = ( $width * $length ) * $values['quantity'];259 $total_flat_area += ( $width * $length ) * $values['quantity']; 250 260 } 251 261 … … 269 279 '[length]', 270 280 '[flat_area]', 281 '[weight]', 271 282 '[cost]', 272 283 ), … … 277 288 $total_length, 278 289 $total_flat_area, 290 $total_weight, 279 291 $package['contents_cost'], 280 292 ), -
deliveryplus-by-invisible-dragon/tags/1.0/id-delivery.php
r2251671 r2282505 7 7 Author URI: https://invisibledragonltd.com/ 8 8 License: Private 9 Version: 1.0.0 9 Version: 1.1.0 10 11 WC requires at least: 3.9 12 WC tested up to: 4.0 10 13 */ 11 14 12 define('ID_DELIVERY_VERSION', '1. 0');15 define('ID_DELIVERY_VERSION', '1.1'); 13 16 14 17 add_action( 'plugins_loaded', array( 'DeliveryPlusPlugin', 'get_instance' ) ); … … 38 41 39 42 return have_rows($key, 'woo_ship_' . $rate->get_instance_id()); 43 44 } 45 46 public static function methods_for_item($product, $destination = null) { 47 48 $package = [ 49 'contents' => [ 50 'single' => [ 51 'quantity' => 1, 52 'data' => $product 53 ] 54 ], 55 'destination' => $destination 56 ]; 57 58 $results = WC()->shipping()->calculate_shipping_for_package($package, time()); 59 60 return $results['rates']; 40 61 41 62 } -
deliveryplus-by-invisible-dragon/tags/1.0/includes/filters.php
r2251671 r2282505 6 6 .id-filter-ui .footer { padding-top: 1.5rem; } 7 7 .id-filter-ui .template { display: none; } 8 .id-filter-ui .id-remove { color: #a00; } 9 .id-filter-ui .id-remove:hover{ color: #c30000; } 8 10 </style> 9 11 <div class="id-filter-ui"> … … 15 17 <thead> 16 18 <tr> 17 <th colspan=" 3">19 <th colspan="4"> 18 20 <?= __('All of the following conditions match:'); ?> 19 21 </th> … … 24 26 <td> 25 27 <select class="id-filter-category"> 26 <?php $categories = DeliveryPlus_Filters::get_categories(); foreach($categories as $ cat): ?>27 <option value="<?= $ cat; ?>"><?= $cat; ?></option>28 <?php $categories = DeliveryPlus_Filters::get_categories(); foreach($categories as $key => $label): ?> 29 <option value="<?= $key; ?>"><?= $label; ?></option> 28 30 <?php endforeach; ?> 29 31 </select> … … 33 35 </td> 34 36 <td> 35 <select class="id-filter-value"></select> 37 <span class="id-filter-value">...</span> 38 </td> 39 <td> 40 <a href="#" class="id-remove id-remove-row" title="<?= __('Remove this row'); ?>"> 41 <span class="dashicons dashicons-trash"></span> 42 </a> 36 43 </td> 37 44 </tr> … … 42 49 <a class="button button-primary id-add-new-and"><?= __('Add new'); ?></a> 43 50 </th> 51 <td> 52 <a href="#" class="id-remove id-remove-block" title="<?= __('Remove this block'); ?>"> 53 <span class="dashicons dashicons-trash"></span> 54 </a> 55 </td> 44 56 </tr> 45 57 </tfoot> -
deliveryplus-by-invisible-dragon/tags/1.0/readme.txt
r2251671 r2282505 4 4 Tags: woocommerce, delivery, gravityforms, acf, advancedcustomfields 5 5 Requires at least: 5.1 6 Tested up to: 5. 3.26 Tested up to: 5.4 7 7 Requires PHP: 7.2 8 8 Stable tag: 4.3 … … 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 11 12 DeliveryPlus provides a delivery option with rate calculation and filter rules. Also integrates with Gravity 13 Forms and Advanced Custom Fields. 12 DeliveryPlus provides a delivery option with rate calculation and filter rules. Also integrates with Gravity Forms and Advanced Custom Fields. 14 13 15 14 == Description == 16 15 17 DeliveryPlus was born out of a need for a clean, easy to use and native delivery method for WooCommerce. This 18 plugin doesn't add any additional tabs to the WordPress menu bar, instead sitting neatly inside of WooCommerce's 19 shipping options as it should, appearing like any other. 16 DeliveryPlus was born out of a need for a clean, easy to use and native delivery method for WooCommerce. This plugin doesn't add any additional tabs to the WordPress menu bar, instead sitting neatly inside of WooCommerce's shipping options as it should, appearing like any other. 20 17 21 Each delivery option can opt to provide a method of calculation, with the available tools displayed on screen, 22 and the ability to filter if the delivery option appears in the checkout under certain conditions. 18 Each delivery option can opt to provide a method of calculation, with the available tools displayed on screen, and the ability to filter if the delivery option appears in the checkout under certain conditions. 23 19 24 The functionality can be extended if the plugin detects Gravity Forms installed, and allows you to pick a 25 form to be displayed on the checkout if your delivery option is selected. Upon order submit, the details 26 are saved and are visible inside of the order view of the WooCommerce admin. 20 The functionality can be extended if the plugin detects Gravity Forms installed, and allows you to pick a form to be displayed on the checkout if your delivery option is selected. Upon order submit, the details are saved and are visible inside of the order view of the WooCommerce admin. 27 21 28 Again, if you have Advanced Custom Fields installed, you can create custom fields which appear inside of 29 the shipping admin area and, with custom code, can be used to create an advanced shipping section on 30 a custom theme. 22 Again, if you have Advanced Custom Fields installed, you can create custom fields which appear inside of the shipping admin area and, with custom code, can be used to create an advanced shipping section on a custom theme. 31 23 32 24 == Installation == 33 25 34 The plugin installs in the standard WordPress fashion. Typically use the Plugins and then Add New and 35 search for the plugin. Or, the manual way: 26 The plugin installs in the standard WordPress fashion. Typically use the Plugins and then Add New and search for the plugin. Or, the manual way: 36 27 37 28 1. Upload the plugin directory to the `/wp-content/plugins/` directory … … 61 52 = 1.0 = 62 53 * Initial Release 54 55 = 1.1 = 56 * Ability to remove conditions if added by mistake 57 * SubTotal condition added 58 * Bugs fixed 59 * Test Suite added 63 60 64 61 == Upgrade Notice == -
deliveryplus-by-invisible-dragon/trunk/admin.js
r2251671 r2282505 8 8 $(".id-filtering").each(function () { 9 9 10 // When category is picked, load next option down 10 11 $(this).on("change", ".id-filter-category", function () { 11 12 var nextDrop = $(".id-filter-condition", $(this).closest("tr")); … … 14 15 nextDrop.html(''); 15 16 for(let key in data) { 16 $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop); 17 var nVal = data[key]; 18 19 $("<option>").attr("value", key).text(nVal['label']).attr("data-type", nVal['type']).appendTo(nextDrop); 17 20 } 18 21 if(nextDrop.attr("data-value")) { 22 // If we need to pre-set, pre-set 19 23 nextDrop.val(nextDrop.attr("data-value")); 20 24 nextDrop.removeAttr("data-value"); 21 25 } 26 // Load default values 22 27 nextDrop.trigger('change'); 23 28 }); 24 29 }); 25 30 31 // When condition type is changed, update dropdown 26 32 $(this).on("change", ".id-filter-condition", function () { 33 // Get the type of the condition value 34 var category = $(".id-filter-category", $(this).closest("tr")).val(); 35 var nextType = $("option:selected", $(this)).attr("data-type"); 36 27 37 var nextDrop = $(".id-filter-value", $(this).closest("tr")); 28 nextDrop.html('<option>...</option>'); 29 var category = $(".id-filter-category", $(this).closest("tr")).val(); 30 $.getJSON(window.ajaxurl + "?action=deliveryplus_get_values&category=" + category +"&condition=" + $(this).val(), function (data) { 31 nextDrop.html(''); 32 for(let key in data) { 33 $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop); 38 var n = $("<div>").addClass("id-filter-value").text("..."); 39 nextDrop.replaceWith(n); 40 nextDrop = n; 41 42 if(nextType == 'pick'){ 43 44 $.getJSON(window.ajaxurl + "?action=deliveryplus_get_values&category=" + category +"&condition=" + $(this).val(), function (data) { 45 var n = $("<select>").addClass("id-filter-value"); 46 nextDrop.replaceWith(n); 47 nextDrop = n; 48 for(let key in data) { 49 $("<option>").attr("value", key).text(data[key]).appendTo(nextDrop); 50 } 51 if(nextDrop.parent().attr("data-value")) { 52 nextDrop.val(nextDrop.parent().attr("data-value")); 53 nextDrop.parent().removeAttr("data-value"); 54 } 55 nextDrop.trigger('change'); 56 }); 57 58 } else if(nextType == 'value'){ 59 60 let n = $("<input>").addClass("id-filter-value input-text").attr("type", "text"); 61 nextDrop.replaceWith(n); 62 nextDrop = n; 63 if(nextDrop.parent().attr("data-value")) { 64 nextDrop.val(nextDrop.parent().attr("data-value")); 65 nextDrop.parent().removeAttr("data-value"); 34 66 } 35 if(nextDrop.attr("data-value")) { 36 nextDrop.val(nextDrop.attr("data-value")); 37 nextDrop.removeAttr("data-value"); 38 } 39 nextDrop.trigger('change'); 40 }); 67 68 }else { 69 nextDrop.text("! " + nextType); 70 } 41 71 }); 42 72 73 // Delete Row 74 $(this).on("click", ".id-remove-row", function(e){ 75 e.preventDefault(); 76 $(this).closest("tr").remove(); 77 }); 78 79 // Delete Block 80 $(this).on("click", ".id-remove-block", function(e){ 81 e.preventDefault(); 82 $(this).closest(".id-filter-set").remove(); 83 }); 84 85 // New Row 43 86 $(this).on("click", ".id-add-new-and", function() { 44 87 newAndCondition($(this).closest("table")); 45 88 }); 46 89 90 // New Block 47 91 $(this).on("click", ".id-add-new-or", function(){ 48 92 newOrCondition(); … … 56 100 $(".id-filter-category", n).val(row['category']); 57 101 $(".id-filter-condition", n).attr("data-value", row['condition']); 58 $(".id-filter-value", n). attr("data-value", row['value']);102 $(".id-filter-value", n).parent().attr("data-value", row['value']); 59 103 } 60 104 … … 75 119 } 76 120 77 let items = JSON.parse($("input", $(".id-filtering").closest('fieldset')).val() || '[]'); 121 // Parse input from saved 122 let items = JSON.parse($("input[type='hidden']", $(".id-filtering").closest('fieldset')).val() || '[]'); 78 123 79 124 if(items.length > 0) { … … 99 144 }); 100 145 101 $("input ", $(".id-filtering").closest('fieldset')).val(JSON.stringify(ret));146 $("input[type='hidden']", $(".id-filtering").closest('fieldset')).val(JSON.stringify(ret)); 102 147 103 148 } 104 149 105 $(this).on("change", "select ", function(){150 $(this).on("change", "select, input[type='text']", function(){ 106 151 renderJSON(); 107 152 }); -
deliveryplus-by-invisible-dragon/trunk/class.DeliveryPlus_Filter_Category.php
r2251671 r2282505 1 1 <?php 2 2 3 class DeliveryPlus_Filter_Category { 3 class DeliveryPlus_Filter_Category extends DeliveryPlus_Filter_Set { 4 5 public static $category = 'Category'; 6 7 public static function category_label(){ return __('Category'); } 4 8 5 9 public static function activate() { 10 parent::activate(); 6 11 add_filter( 'deliveryplus_filter_Category_1', array( static::class, 'at_least_one' ), 10, 3 ); 7 12 add_filter( 'deliveryplus_filter_Category_!', array( static::class, 'none' ), 10, 3 ); 8 13 add_filter( 'deliveryplus_filter_Category_!a', array( static::class, 'not_all' ), 10, 3 ); 9 14 add_filter( 'deliveryplus_filter_Category_a', array( static::class, 'all' ), 10, 3 ); 15 } 16 17 public static function get_conditions($conditions) { 18 $ret['1'] = new DPF_Pick_Value(__('at least one in')); 19 $ret['a'] = new DPF_Pick_Value(__('all must be in')); 20 $ret['!'] = new DPF_Pick_Value(__('none must be in')); 21 $ret['!a'] = new DPF_Pick_Value(__('not all in')); 22 return $ret; 23 } 24 25 public static function get_values($ret, $condition) { 26 $raw = get_categories(array('taxonomy' => 'product_cat', 'hide_empty' => false)); 27 foreach($raw as $cat) { 28 $ret[$cat->term_id] = wp_specialchars_decode( $cat->name ); 29 } 30 return $ret; 10 31 } 11 32 -
deliveryplus-by-invisible-dragon/trunk/class.DeliveryPlus_Filters.php
r2251671 r2282505 1 1 <?php 2 2 3 require_once "class.DeliveryPlus_Filter_Category.php"; 3 /** 4 * This is a standard DeliveryPlus condition, specifying the value for this 5 * condition should be entered into a textbox 6 */ 7 class DPF_Value { 8 9 public $type = 'value'; 10 11 public function __construct($label) { 12 $this->label = $label; 13 } 14 15 public function toJSON() { 16 return array( 17 'type' => $this->type, 18 'label' => $this->label 19 ); 20 } 21 22 } 23 24 /** 25 * This is a variation of a DeliveryPlus conditon, whereby the value 26 * needs to be picked from a dropdown list. 27 */ 28 class DPF_Pick_Value extends DPF_Value { 29 30 public $type = 'pick'; 31 32 } 33 34 abstract class DeliveryPlus_Filter_Set { 35 36 public static $category = 'Unknown'; 37 public static function category_label(){ return __('Unknown'); } 38 39 public static function activate() { 40 41 add_filter( 'deliveryplus_categories', array( static::class, 'add_category' ) ); 42 add_filter( 'deliveryplus_values_' . static::$category, array( static::class, 'get_values' ), 10, 2 ); 43 add_filter( 'deliveryplus_conditions_' . static::$category, array( static::class, 'get_conditions' ) ); 44 45 // Now associate a filter function for each condition 46 $conditions = static::get_conditions(array()); 47 foreach($conditions as $key => $val) { 48 add_filter( 'deliveryplus_filter_' . static::$category . '_' . $key, array( static::class, 'do_' . $key ), 10, 3 ); 49 } 50 51 } 52 53 abstract public static function get_conditions($conditions); 54 55 public static function get_values($ret, $condition){ 56 // TODO by sub-function 57 return $ret; 58 } 59 60 public static function add_category($filters) { 61 $filters[static::$category] = static::category_label(); 62 return $filters; 63 } 64 } 65 4 66 5 67 class DeliveryPlus_Filters { … … 9 71 add_action( 'wp_ajax_deliveryplus_get_values', array( static::class, 'get_values_ajax' ) ); 10 72 73 // Activate default filters 74 require_once "class.DeliveryPlus_Filter_Number.php"; 75 require_once "class.DeliveryPlus_Filter_Weight.php"; 76 require_once "class.DeliveryPlus_Filter_Category.php"; 77 require_once "class.DeliveryPlus_Filter_SubTotal.php"; 78 11 79 DeliveryPlus_Filter_Category::activate(); 80 DeliveryPlus_Filter_SubTotal::activate(); 81 DeliveryPlus_Filter_Weight::activate(); 12 82 } 13 83 … … 26 96 public static function get_categories() { 27 97 28 $categories[] = 'Category'; 29 30 $categories = apply_filters( 'deliveryplus_categories', $categories ); 98 $categories = apply_filters( 'deliveryplus_categories', array() ); 31 99 32 100 return $categories; … … 37 105 38 106 $ret = []; 39 40 if($category == 'Category') { 41 $raw = get_categories(array('taxonomy' => 'product_cat', 'hide_empty' => false)); 42 foreach($raw as $cat) { 43 $ret[$cat->term_id] = wp_specialchars_decode( $cat->name ); 44 } 45 } 46 47 $ret = apply_filters( 'deliveryplus_values_' . $category, $ret ); 107 $ret = apply_filters( 'deliveryplus_values_' . $category, $ret, $condition ); 48 108 49 109 return $ret; … … 64 124 65 125 $ret = []; 66 67 if($category == 'Category') {68 $ret['1'] = 'at least one in';69 $ret['a'] = 'all must be in';70 $ret['!'] = 'none must be in';71 $ret['!a'] = 'not all in';72 }73 74 126 $ret = apply_filters( 'deliveryplus_conditions_' . $category, $ret ); 75 127 … … 84 136 public static function filter_block_package( $block, $package ) { 85 137 138 if(empty($block)) { 139 return true; 140 } 141 86 142 foreach( $block as $rule ) { 87 143 88 144 $filter = 'deliveryplus_filter_' . $rule['category'] . '_' . $rule['condition']; 89 145 if(!apply_filters($filter, false, $package, $rule)) { 90 var_dump($filter);91 146 return false; 92 147 } … … 99 154 100 155 public static function filter_package( $filters, $package ) { 156 157 if(empty($filters)) { 158 return true; 159 } 101 160 102 161 foreach($filters as $block) { -
deliveryplus-by-invisible-dragon/trunk/class.DeliveryPlus_Shipping_Method.php
r2251671 r2282505 31 31 'default' => __( 'DeliveryPlus' ) 32 32 ), 33 'tax_status' => array( 34 'title' => __( 'Tax status', 'woocommerce' ), 35 'type' => 'select', 36 'class' => 'wc-enhanced-select', 37 'default' => 'taxable', 38 'options' => array( 39 'taxable' => __( 'Taxable', 'woocommerce' ), 40 'none' => _x( 'None', 'Tax status', 'woocommerce' ), 41 ), 42 ), 33 43 'rate' => array( 34 44 'title' => __( 'Rate' ), … … 247 257 // Now we can do some area calculations 248 258 if($width && $length){ 249 $total_flat_area = ( $width * $length ) * $values['quantity'];259 $total_flat_area += ( $width * $length ) * $values['quantity']; 250 260 } 251 261 … … 269 279 '[length]', 270 280 '[flat_area]', 281 '[weight]', 271 282 '[cost]', 272 283 ), … … 277 288 $total_length, 278 289 $total_flat_area, 290 $total_weight, 279 291 $package['contents_cost'], 280 292 ), -
deliveryplus-by-invisible-dragon/trunk/id-delivery.php
r2251671 r2282505 7 7 Author URI: https://invisibledragonltd.com/ 8 8 License: Private 9 Version: 1.0.0 9 Version: 1.1.0 10 11 WC requires at least: 3.9 12 WC tested up to: 4.0 10 13 */ 11 14 12 define('ID_DELIVERY_VERSION', '1. 0');15 define('ID_DELIVERY_VERSION', '1.1'); 13 16 14 17 add_action( 'plugins_loaded', array( 'DeliveryPlusPlugin', 'get_instance' ) ); … … 38 41 39 42 return have_rows($key, 'woo_ship_' . $rate->get_instance_id()); 43 44 } 45 46 public static function methods_for_item($product, $destination = null) { 47 48 $package = [ 49 'contents' => [ 50 'single' => [ 51 'quantity' => 1, 52 'data' => $product 53 ] 54 ], 55 'destination' => $destination 56 ]; 57 58 $results = WC()->shipping()->calculate_shipping_for_package($package, time()); 59 60 return $results['rates']; 40 61 41 62 } -
deliveryplus-by-invisible-dragon/trunk/includes/filters.php
r2251671 r2282505 6 6 .id-filter-ui .footer { padding-top: 1.5rem; } 7 7 .id-filter-ui .template { display: none; } 8 .id-filter-ui .id-remove { color: #a00; } 9 .id-filter-ui .id-remove:hover{ color: #c30000; } 8 10 </style> 9 11 <div class="id-filter-ui"> … … 15 17 <thead> 16 18 <tr> 17 <th colspan=" 3">19 <th colspan="4"> 18 20 <?= __('All of the following conditions match:'); ?> 19 21 </th> … … 24 26 <td> 25 27 <select class="id-filter-category"> 26 <?php $categories = DeliveryPlus_Filters::get_categories(); foreach($categories as $ cat): ?>27 <option value="<?= $ cat; ?>"><?= $cat; ?></option>28 <?php $categories = DeliveryPlus_Filters::get_categories(); foreach($categories as $key => $label): ?> 29 <option value="<?= $key; ?>"><?= $label; ?></option> 28 30 <?php endforeach; ?> 29 31 </select> … … 33 35 </td> 34 36 <td> 35 <select class="id-filter-value"></select> 37 <span class="id-filter-value">...</span> 38 </td> 39 <td> 40 <a href="#" class="id-remove id-remove-row" title="<?= __('Remove this row'); ?>"> 41 <span class="dashicons dashicons-trash"></span> 42 </a> 36 43 </td> 37 44 </tr> … … 42 49 <a class="button button-primary id-add-new-and"><?= __('Add new'); ?></a> 43 50 </th> 51 <td> 52 <a href="#" class="id-remove id-remove-block" title="<?= __('Remove this block'); ?>"> 53 <span class="dashicons dashicons-trash"></span> 54 </a> 55 </td> 44 56 </tr> 45 57 </tfoot> -
deliveryplus-by-invisible-dragon/trunk/readme.txt
r2251671 r2282505 4 4 Tags: woocommerce, delivery, gravityforms, acf, advancedcustomfields 5 5 Requires at least: 5.1 6 Tested up to: 5. 3.26 Tested up to: 5.4 7 7 Requires PHP: 7.2 8 8 Stable tag: 4.3 … … 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 11 12 DeliveryPlus provides a delivery option with rate calculation and filter rules. Also integrates with Gravity 13 Forms and Advanced Custom Fields. 12 DeliveryPlus provides a delivery option with rate calculation and filter rules. Also integrates with Gravity Forms and Advanced Custom Fields. 14 13 15 14 == Description == 16 15 17 DeliveryPlus was born out of a need for a clean, easy to use and native delivery method for WooCommerce. This 18 plugin doesn't add any additional tabs to the WordPress menu bar, instead sitting neatly inside of WooCommerce's 19 shipping options as it should, appearing like any other. 16 DeliveryPlus was born out of a need for a clean, easy to use and native delivery method for WooCommerce. This plugin doesn't add any additional tabs to the WordPress menu bar, instead sitting neatly inside of WooCommerce's shipping options as it should, appearing like any other. 20 17 21 Each delivery option can opt to provide a method of calculation, with the available tools displayed on screen, 22 and the ability to filter if the delivery option appears in the checkout under certain conditions. 18 Each delivery option can opt to provide a method of calculation, with the available tools displayed on screen, and the ability to filter if the delivery option appears in the checkout under certain conditions. 23 19 24 The functionality can be extended if the plugin detects Gravity Forms installed, and allows you to pick a 25 form to be displayed on the checkout if your delivery option is selected. Upon order submit, the details 26 are saved and are visible inside of the order view of the WooCommerce admin. 20 The functionality can be extended if the plugin detects Gravity Forms installed, and allows you to pick a form to be displayed on the checkout if your delivery option is selected. Upon order submit, the details are saved and are visible inside of the order view of the WooCommerce admin. 27 21 28 Again, if you have Advanced Custom Fields installed, you can create custom fields which appear inside of 29 the shipping admin area and, with custom code, can be used to create an advanced shipping section on 30 a custom theme. 22 Again, if you have Advanced Custom Fields installed, you can create custom fields which appear inside of the shipping admin area and, with custom code, can be used to create an advanced shipping section on a custom theme. 31 23 32 24 == Installation == 33 25 34 The plugin installs in the standard WordPress fashion. Typically use the Plugins and then Add New and 35 search for the plugin. Or, the manual way: 26 The plugin installs in the standard WordPress fashion. Typically use the Plugins and then Add New and search for the plugin. Or, the manual way: 36 27 37 28 1. Upload the plugin directory to the `/wp-content/plugins/` directory … … 61 52 = 1.0 = 62 53 * Initial Release 54 55 = 1.1 = 56 * Ability to remove conditions if added by mistake 57 * SubTotal condition added 58 * Bugs fixed 59 * Test Suite added 63 60 64 61 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.