From b3ae23e5080565802ba706f5d3a74d929d5d9c72 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Sat, 13 Aug 2016 01:06:25 +0200 Subject: [PATCH] Convert the Shipping by Rules plugins to the new WC shipping zones. The old functionality (with its own country handling and multiple method handling) is retained via a legacy shipping method and deprecated. --- Makefile | 2 +- assets/css/admin-styles.css | 122 +++--------- assets/css/legacy-admin-styles.css | 93 +++++++++ ....js => legacy-shipping-by-rules-config.js} | 0 assets/js/opentools-updatecheck.js | 36 ++-- includes/admin/html/html-shipping-methods.php | 158 +++++---------- includes/admin/html/html-upgrade-nag.php | 6 +- includes/rules-shipping-method.php | 146 +++++++++----- .../rules_shipping_framework_woocommerce.php | 44 +---- .../admin/html/html-shipping-methods.php | 134 +++++++++++++ .../admin/html/html-upgrade-nag.php | 28 +++ .../admin/settings/meta-box-field-ruleset.php | 0 .../admin/settings/meta-box-help.php | 51 +++++ .../admin/settings/meta-box-rulesets.php | 0 .../admin/settings/meta-box-settings.php | 0 .../legacy-rules-shipping-method.php | 184 ++++++++++++++++++ .../legacy-rules-shipping-post-type.php | 4 +- ...y-rules_shipping_framework_woocommerce.php | 90 +++++++++ ...hipping_framework_woocommerce_advanced.php | 52 +++++ ...woocommerce-advanced-shipping-by-rules.php | 139 +++++++++++++ legacy-woocommerce-shipping-by-rules.php | 137 +++++++++++++ readme-adv.txt | 2 +- readme.txt | 5 +- woocommerce-advanced-shipping-by-rules.php | 44 ++--- woocommerce-shipping-by-rules.php | 42 ++-- 25 files changed, 1149 insertions(+), 370 deletions(-) create mode 100644 assets/css/legacy-admin-styles.css rename assets/js/{shipping-by-rules-config.js => legacy-shipping-by-rules-config.js} (100%) create mode 100644 legacy-includes/admin/html/html-shipping-methods.php create mode 100644 legacy-includes/admin/html/html-upgrade-nag.php rename {includes => legacy-includes}/admin/settings/meta-box-field-ruleset.php (100%) create mode 100644 legacy-includes/admin/settings/meta-box-help.php rename {includes => legacy-includes}/admin/settings/meta-box-rulesets.php (100%) rename {includes => legacy-includes}/admin/settings/meta-box-settings.php (100%) create mode 100644 legacy-includes/legacy-rules-shipping-method.php rename includes/rules-shipping-post-type.php => legacy-includes/legacy-rules-shipping-post-type.php (99%) create mode 100644 legacy-includes/legacy-rules_shipping_framework_woocommerce.php create mode 100644 legacy-includes/legacy-rules_shipping_framework_woocommerce_advanced.php create mode 100644 legacy-woocommerce-advanced-shipping-by-rules.php create mode 100644 legacy-woocommerce-shipping-by-rules.php diff --git a/Makefile b/Makefile index e3fb79b..218f2c9 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ BASE=shipping-by-rules PLATTFORM=woocommerce VENDOR=opentools -VERSION=1.2.5 +VERSION=1.3.0 DIR = $(shell pwd) SVNDIR=wordpress-plugin-svn diff --git a/assets/css/admin-styles.css b/assets/css/admin-styles.css index 8e2a3bb..233e6f4 100644 --- a/assets/css/admin-styles.css +++ b/assets/css/admin-styles.css @@ -1,109 +1,24 @@ -table.rules_shipping_methods th { - padding-left: 10px; -} -table.rules_shipping_methods .name { - -} -table.rules_shipping_methods.widefat { - background: inherited; -} - -div.shipping_rules_ruleset { - background: #f8f8f8; - border: #D0D0D0 1px solid; - margin-bottom: 20px; - margin-top: 20px; -} - -#shipping_rules_rulesets .ruleset_openclose { - cursor: pointer; - float: right; - width: 27px; - height: 30px; -} -#shipping_rules_rulesets .shipping_rules_ruleset.closed .inside { - display: none; -} - -#shipping_rules_rulesets .shipping_rules_ruleset.closed .ruleset_openclose:before { - content: '\f140'; -} -#shipping_rules_rulesets .shipping_rules_ruleset .ruleset_openclose:before { - content: '\f142'; -} -#shipping_rules_rulesets .ruleset_openclose:before { -/* right: 12px; */ - font: 400 20px/1 dashicons; - speak: none; - display: inline-block; - padding: 2px; - top: 0; - position: relative; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - text-decoration: none!important; - width: 100%; - height: 100%; -} - -#poststuff div.shipping_rules_ruleset h3 { - padding: 6px 3px; -} - -.form-table td.shipping_rules_rulescell { - padding-left: 0; -} - -.form-table textarea.shipping_rules_rule_textarea { - width: 100%; -} -#shipping_rules_rulesets .form-table th.titledesc { - padding-bottom: 12px; - padding-top: 8px; - font-weight: normal; - -} -#shipping_rules_rulesets .form-table td.forminp { - padding-bottom: 0; - padding-top: 0; -} - - -.ruleset-box-header { - width: 100%; - height: 30px; -/* border: 1px solid #808080; */ - border-bottom: 1px solid #D0D0D0; -} -.ruleset-box-header .input-wrap { - display: block; - overflow: hidden; - height: 100%; -} -.ruleset-box-header input.ruleset_name { - width: 100%; - margin: 2px 0; -} -.ruleset-box-header .ruleset_name_label { - float: left; - height: 100%; - margin-top: 0; - margin-bottom: 0; -} - +/*******************************/ +/* CSS for the Upgrade NAG Box */ +/*******************************/ div#opentools-shippingbyrules-upgrade { padding: 5px 10px; } div#opentools-shippingbyrules-upgrade.postbox { display: inline-block; } -div#opentools-shippingbyrules-upgrade h3 { +#opentools-shippingbyrules-upgrade h3 { + margin: 0; + border-bottom: #800000 solid 1px; + margin-top: 3px; + padding-bottom: 3px; } div#opentools-shippingbyrules-upgrade ul { list-style: disc; /* list-style-position: inside; */ margin-left: 5px; padding-left: 5px; + margin-top: 5px; } div#opentools-shippingbyrules-upgrade li { margin-left: 2em; @@ -121,6 +36,12 @@ div#opentools-shippingbyrules-upgrade .logoleft { div#opentools-shippingbyrules-upgrade .contents { padding-left: 120px; } + + + +/*******************************/ +/* CSS for the rules help Box */ +/*******************************/ ul.otsr_list, ul.otsr_list ul { list-style: disc; padding-left: 10px; @@ -135,4 +56,17 @@ ul.otsr_list blockquote { background: #f0f0f0; margin: 0; padding: 0.2em 0.5em; +} + + +/************************************/ +/* CSS for the Shipping methods box */ +/************************************/ +table.rules_shipping_methods.wc-shipping-zones td li, table.rules_shipping_methods.wc-shipping-zones th li { + line-height: 1.15em; +} +table.rules_shipping_methods.wc-shipping-zones td, table.rules_shipping_methods.wc-shipping-zones th { + line-height: 1.15em; + padding-top: 5px; + padding-bottom: 5px; } \ No newline at end of file diff --git a/assets/css/legacy-admin-styles.css b/assets/css/legacy-admin-styles.css new file mode 100644 index 0000000..195b669 --- /dev/null +++ b/assets/css/legacy-admin-styles.css @@ -0,0 +1,93 @@ +table.rules_shipping_methods th { + padding-left: 10px; +} +table.rules_shipping_methods .name { + +} +table.rules_shipping_methods.widefat { + background: inherited; +} + +div.shipping_rules_ruleset { + background: #f8f8f8; + border: #D0D0D0 1px solid; + margin-bottom: 20px; + margin-top: 20px; +} + +#shipping_rules_rulesets .ruleset_openclose { + cursor: pointer; + float: right; + width: 27px; + height: 30px; +} +#shipping_rules_rulesets .shipping_rules_ruleset.closed .inside { + display: none; +} + +#shipping_rules_rulesets .shipping_rules_ruleset.closed .ruleset_openclose:before { + content: '\f140'; +} +#shipping_rules_rulesets .shipping_rules_ruleset .ruleset_openclose:before { + content: '\f142'; +} +#shipping_rules_rulesets .ruleset_openclose:before { +/* right: 12px; */ + font: 400 20px/1 dashicons; + speak: none; + display: inline-block; + padding: 2px; + top: 0; + position: relative; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + text-decoration: none!important; + width: 100%; + height: 100%; +} + +#poststuff div.shipping_rules_ruleset h3 { + padding: 6px 3px; +} + +.form-table td.shipping_rules_rulescell { + padding-left: 0; +} + +.form-table textarea.shipping_rules_rule_textarea { + width: 100%; +} +#shipping_rules_rulesets .form-table th.titledesc { + padding-bottom: 12px; + padding-top: 8px; + font-weight: normal; + +} +#shipping_rules_rulesets .form-table td.forminp { + padding-bottom: 0; + padding-top: 0; +} + + +.ruleset-box-header { + width: 100%; + height: 30px; +/* border: 1px solid #808080; */ + border-bottom: 1px solid #D0D0D0; +} +.ruleset-box-header .input-wrap { + display: block; + overflow: hidden; + height: 100%; +} +.ruleset-box-header input.ruleset_name { + width: 100%; + margin: 2px 0; +} +.ruleset-box-header .ruleset_name_label { + float: left; + height: 100%; + margin-top: 0; + margin-bottom: 0; +} + diff --git a/assets/js/shipping-by-rules-config.js b/assets/js/legacy-shipping-by-rules-config.js similarity index 100% rename from assets/js/shipping-by-rules-config.js rename to assets/js/legacy-shipping-by-rules-config.js diff --git a/assets/js/opentools-updatecheck.js b/assets/js/opentools-updatecheck.js index 3f8f407..2eed40a 100644 --- a/assets/js/opentools-updatecheck.js +++ b/assets/js/opentools-updatecheck.js @@ -5,21 +5,27 @@ var showUpdateCredentialsRow = function (btn) { var ajaxurl = jQuery(btn).data('ajaxurl'); var slug = jQuery(btn).data("slug"); var nonce = jQuery(btn).data("nonce"); - var ajaxargs = { - type: "POST", - url: ajaxurl, - data: { - action: 'getUpdateCredentialsRow_'+slug, - slug: slug, - _ajax_nonce: nonce - }, - success: function ( json ) { - jQuery(btn).closest('tr').after(json['row']); - }, - error: function() { }, - complete: function() { }, - }; - jQuery.ajax(ajaxargs); + + var credentialRow = jQuery(btn).closest('table').find('tr#'+slug+'-credentials'); + if (credentialRow.length > 0) { + jQuery(credentialRow).fadeOut(1000, function() { jQuery(this).remove(); }); + } else { + var ajaxargs = { + type: "POST", + url: ajaxurl, + data: { + action: 'getUpdateCredentialsRow_'+slug, + slug: slug, + _ajax_nonce: nonce + }, + success: function ( json ) { + jQuery(btn).closest('tr').after(json['row']); + }, + error: function() { }, + complete: function() { }, + }; + jQuery.ajax(ajaxargs); + } return false; }; diff --git a/includes/admin/html/html-shipping-methods.php b/includes/admin/html/html-shipping-methods.php index a0eb924..357d84a 100644 --- a/includes/admin/html/html-shipping-methods.php +++ b/includes/admin/html/html-shipping-methods.php @@ -3,132 +3,70 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -$methods = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'shipping_rules', 'post_status' => array( 'draft', 'publish' ) ) ); +$methods = array(); ?> <tr valign="top"> - <th scope="row" class="titledesc"><?php echo $this->helper->__( 'Shipping By Rules Methods' ) ?></th> - <td class="forminp" id="<?php echo $this->id; ?>_rules_shipping_methods"> + <th colspan="2" scope="row" class="titledesc"><?php echo $this->helper->__( 'Configured Shipping By Rules Methods in all shipping zones' ) ?></th> +</tr> +<tr valign="top"> + <td colspan="2" class="forminp" id="<?php echo $this->id; ?>_rules_shipping_methods"><?php echo sprintf($this->helper->__( 'This table shows <a href="%s">all shipping zones</a> and for each zone the shipping methods provided by this plugin.' ), admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); ?> - <table class="rules_shipping_methods widefat striped" cellspacing="0"> + <table class="rules_shipping_methods wc-shipping-zones widefat striped" cellspacing="0"> <thead> <tr> - <th class="name" ><?php echo $this->helper->__( 'Name' ); ?></th> - <th class="id" ><?php echo $this->helper->__( 'ID' ); ?></th> - <th class="status" ><?php echo $this->helper->__( 'Status' ); ?></th> - <th class="methods" ><?php echo $this->helper->__( 'Configured Rulesets' ); ?></th> + <th class="name" ><?php echo $this->helper->__( 'Zone name' ); ?></th> + <th class="methods" ><?php echo $this->helper->__( 'Configured Shipping by Rules methods' ); ?></th> + <th class="methods" ><?php echo $this->helper->__( 'Other methods' ); ?></th> </tr> </thead> - <tbody> + <tbody class="wc-shipping-zone-rows"> <?php - $i = 0; - foreach ( $methods as $method ) { - $alt = ''; -// $alt = ( $i++ ) % 2 == 0 ? 'alternate' : ''; - ?> - <tr> - <td class="name <?php echo $alt; ?>"> - <input type="hidden" name="rules_method_order[]" value="<?php echo esc_attr($method->ID); ?>" /> - <?php echo empty($method->post_title) ? $this->helper->__('Untitled Method') : esc_html($method->post_title); ?> - <div class='row-actions'> - <span class='edit'> - <a href='<?php echo get_edit_post_link( $method->ID ); ?>' title='<?php echo $this->helper->__( 'Edit Method'); ?>'> - <?php echo $this->helper->__('Edit'); ?> - </a> - | - </span> - <span class='trash'> - <a href='<?php echo get_delete_post_link( $method->ID ); ?>' title='<?php echo $this->helper->__('Delete Method'); ?>'><?php - echo $this->helper->__('Delete'); - ?></a> - </span> - </div> - </td> - <td class="id"> - <?php echo esc_html($method->ID); ?> - </td> - <td class="status"> - - <?php - if ( $method->post_status == 'publish' ) { ?> - <span class="status-enabled tips" data-tip="<?php echo __ ( 'Enabled', 'woocommerce' ); ?>"><?php echo __ ( 'Enabled', 'woocommerce' ); ?></span> + $zones = WC_Shipping_Zones::get_zones(); + // get_zones does NOT include the global (fallback) zone => add it manually! + $globalshippingzone = new WC_Shipping_Zone(0); + $globalzone = $globalshippingzone->get_data(); + $globalzone['formatted_zone_location'] = $globalshippingzone->get_formatted_location(); + $globalzone['shipping_methods'] = $globalshippingzone->get_shipping_methods(); + $zones[] = $globalzone; + foreach ($zones as $zone) { + ?> + <tr> + <td class="name"><a href="<?php echo admin_url(sprintf('admin.php?page=wc-settings&tab=shipping&zone_id=%d', $zone['zone_id'] )); ?>"><?php echo $zone['zone_name']; ?> (<?php echo $zone['formatted_zone_location']; ?>)</a></td> + <td class="methods wc-shipping-zone-methods "> + <ul> <?php - } else { - echo '-'; - } - ?> - + foreach ($zone['shipping_methods'] as $method) { + if ($method->id == 'shipping_by_rules') { + $methodclass = ($method->enabled=='no')?'method_disabled':'method_enabled'; + $methodurl = admin_url(sprintf('admin.php?page=wc-settings&tab=shipping&instance_id=%d', $method->instance_id)); + ?> + <li class="<?php echo $methodclass;?>"><a href="<?php echo $methodurl;?>"><?php echo $method->title; ?></a></li> + <?php + } +// print_r($method); + } ?> + </ul> </td> - <td> + <td class="methods wc-shipping-zone-methods "> + <ul> <?php - $rulesetnames = array(); - $rulesets = get_post_meta( $method->ID, '_rules_shipping_ruleset', true ); - if (!is_array($rulesets)) { - $rulesets = array(); + foreach ($zone['shipping_methods'] as $method) { + if ($method->id != 'shipping_by_rules') { + $methodclass = ($method->enabled=='no')?'method_disabled':'method_enabled'; + ?> + <li class="<?php echo $methodclass;?>"><?php echo $method->title; ?></li> + <?php } - foreach ($rulesets as $ruleset) { - if (isset($ruleset['name']) && !empty($ruleset['name'])) { - $rulesetnames[] = $ruleset['name']; - } else { - $rulesetnames[] = $this->helper->__('<Unnamed>'); - } - } - if (!empty($rulesetnames)) { - echo esc_html(join(", ", $rulesetnames)); - } else { - echo $this->helper->__('<em>No rulesets defined</em>'); - } - ?> + } ?> + </ul> </td> </tr> - <?php - } - - if ( empty( $methods ) ) : - - ?><tr> - <td colspan='4'><?php echo $this->helper->__( 'There are no Shipping By Rules methods configured yet.' ); ?></td> - </tr><?php - endif; - - ?></tbody> - <tfoot> - <tr> - <th colspan='1' style='padding-left: 10px;'> - <a href='<?php echo admin_url( 'post-new.php?post_type=shipping_rules' ); ?>' class='add button'><?php echo $this->helper->__( 'Add Shipping By Rules method' ); ?></a> - </th> - <th colspan="3"> - <span class="description"><?php _e( 'Drag and drop the above shipping methods to control their display order.', 'woocommerce' ); ?></span> - </th> - </tr> - </tfoot> + <?php + } ?> + </tbody> </table> - <script type="text/javascript"> - jQuery(function() { - - // Sorting - jQuery('table.rules_shipping_methods tbody').sortable({ - items:'tr', - cursor:'move', - axis:'y', - handle: 'td', - scrollSensitivity:40, - helper:function(e,ui){ - ui.children().each(function(){ - jQuery(this).width(jQuery(this).width()); - }); -// ui.css('left', '0'); - return ui; - }, - start:function(event,ui){ - ui.item.css('background-color','#f6f6f6'); - }, - stop:function(event,ui){ - ui.item.removeAttr('style'); - } - }); - }); - </script> </td> </tr> + <?php diff --git a/includes/admin/html/html-upgrade-nag.php b/includes/admin/html/html-upgrade-nag.php index c557306..c917f31 100644 --- a/includes/admin/html/html-upgrade-nag.php +++ b/includes/admin/html/html-upgrade-nag.php @@ -11,16 +11,14 @@ if ( ! defined( 'ABSPATH' ) ) { <div class="logoleft"><a href="<?php echo esc_html($settings['link']); ?>"><img src="<?php echo plugins_url('../../../assets/images/advlogo100.png', __FILE__); ?>"></a></div> <!--p>Advanced features not included in the free plugin include:</p--> <ul> - <li><b>Mathematical expressions</b>: shipping costs calculated from mathematical expressions (depending on weight, dimensions, amount, etc.): + <li><b>Mathematical expressions</b> for shipping costs (depending on weight, dimensions, amount, etc.): <ul style="font-size: smaller"> <li>Shipping costs per kg</li> <li>Percentage shipping cost on the amount, etc.</li> </ul> - <li><b>List functions</b>: conditions on certain products, categories, tags or shipping classes</li> - <li><b>Conditions for product subsets</b>: Conditions and shipping costs depending on values evaluated only for particular products, categories, tags or shipping classes + <li><b>Conditions for product subsets</b>: Conditions / costs depending on particular products, categories, tags or shipping classes <li><b>Alphanumeric Postcodes</b>: Conditions on UK and Canadian postcodes</li> <li><b>Coupon Codes</b>: conditions on coupon codes</li> - <li>...</li> </ul> <p>More information and purchase: <a class="button-primary" href="<?php echo esc_html($settings['link']); ?>" target="_blank">Get Support and advanced features</a></p> </div> diff --git a/includes/rules-shipping-method.php b/includes/rules-shipping-method.php index fe5f0f7..e9a1f48 100644 --- a/includes/rules-shipping-method.php +++ b/includes/rules-shipping-method.php @@ -8,6 +8,10 @@ * License: GPLv3+ */ +if (!defined('ABSPATH')) { + exit; +} + class Shipping_by_Rules extends WC_Shipping_Method { protected $helper = null; /** @@ -16,7 +20,7 @@ class Shipping_by_Rules extends WC_Shipping_Method { * @access public * @return void */ - public function __construct() { + public function __construct($instance_id = 0) { if (class_exists("RulesShippingFrameworkWooCommerceAdvanced")) { $this->helper = RulesShippingFrameworkWooCommerceAdvanced::getHelper(); } else { @@ -26,9 +30,14 @@ class Shipping_by_Rules extends WC_Shipping_Method { $this->helper = RulesShippingFrameworkWooCommerce::getHelper(); } $this->id = 'shipping_by_rules'; // Id for your shipping method. Should be unique. - $this->title = $this->helper->__( 'Shipping By Rules'); + $this->instance_id = absint( $instance_id ); $this->method_title = $this->helper->__( 'Shipping by Rules' ); // Title shown in admin $this->method_description = $this->helper->__( 'Define shipping costs by general, text-based rules.' ); // Description shown in admin + $this->supports = array( + 'settings', // Global settings (not instance-specific) + 'shipping-zones', + 'instance-settings', + ); $this->init(); } @@ -44,39 +53,76 @@ class Shipping_by_Rules extends WC_Shipping_Method { * @return void */ function init() { + $this->instance_form_fields = $this->define_instance_form_fields(); + $this->form_fields = $this->define_global_form_fields(); + $this->title = $this->get_option('title'); + $this->tax_status = $this->get_option('tax_status'); + $this->rules = $this->get_option('rules'); + + $this->init_form_fields(); $this->init_settings(); - $this->enabled = $this->get_option ('enabled'); - // Save settings in admin if you have any defined add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); - add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_shipping_rules_sorting' ) ); } - - /** - * Initialise Settings Form Fields - * - * @access public - * @return void - */ - public function init_form_fields() { - add_filter( 'woocommerce_admin_field_opentools_shippingbyrules_upgrade', array( &$this, 'admin_field_opentools_shippingbyrules_upgrade') ); - $fields = array_merge( + + function define_global_form_fields() { + return array_merge( $this->helper->getUpgradeNagSettings(), array( - 'enabled' => array( - 'title' => __( 'Enable/Disable', 'woocommerce' ), - 'type' => 'checkbox', - 'label' => $this->helper->__( 'Enable Shipping By Rules'), - 'default' => 'yes' +/* 'debug' => array( + 'title' => $this->helper->__('Enable debug messages'), + 'type' => 'checkbox', + 'label' => $this->helper->__('If enabled and WP_DEBUG is set, all defined variables and their values are printed into the WordPress debug log.' ), + 'default' => 'no' ), + 'global_rules' => array( + 'title' => $this->helper->__('Global definitions:'), + 'type' => 'textarea', + 'css' => '', + 'description' => $this->helper->__('Global definitions are prepended to all rule sets and will be available in all Shipping by Rules methods of all shipping zones. Do NOT include a rule that sets Shipping=... or NoShipping, as this will override all other rules!'), + 'class' => 'shipping_rules_rule_textarea', + 'placeholder' => $this->helper->__('Definitions of the form: Variable=MyVar; Amount>100; [...Conditions...]; Value=123'), + ),*/ 'methods' => array( 'type' => 'rules_shipping_methods', ), ) ); - $this->form_fields = $fields; + } + + function define_instance_form_fields() { + return array_merge( + $this->helper->getUpgradeNagSettings(), + + array( + 'title' => array( + 'title' => __( 'Method Title', 'woocommerce' ), + 'type' => 'text', + 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), + 'default' => __( 'Shipping by Rules', 'woocommerce' ), + 'desc_tip' => true + ), + 'tax_status' => array( + 'title' => __( 'Tax Status', 'woocommerce' ), + 'type' => 'select', + 'class' => 'wc-enhanced-select', + 'default' => 'taxable', + 'options' => array( + 'taxable' => __( 'Taxable', 'woocommerce' ), + 'none' => _x( 'None', 'Tax status', 'woocommerce' ) + ) + ), + 'rules' => array( + 'title' => __('Rules:', 'opentools-shippingrules'), + 'type' => 'textarea', + 'css' => '', + 'class' => 'shipping_rules_rule_textarea', + 'placeholder' => __('Rules of the form: Name="Rule name"; Amount>100; [...Conditions...]; Shipping=3', 'opentools-shippingrules'), + ), + ) + ); } /** @@ -104,6 +150,25 @@ class Shipping_by_Rules extends WC_Shipping_Method { return false; } + + public function getUpgradeNagSettings() { + $settings = array(); + if (!$this->isAdvanced()) { + add_filter( 'woocommerce_admin_field_opentools_shippingbyrules_upgrade', array( &$this, 'admin_field_opentools_shippingbyrules_upgrade') ); + $settings['opentools_shippingbyrules_upgrade'] = array( + 'name' => $this->__( 'Upgrade to the ADVANCED VERSION of the OpenTools Shipping by Rules plugin'), + 'type' => 'opentools_shippingbyrules_upgrade', + 'link' => 'http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html', + ); + } + return $settings; + } + + public function printUpgradeNagBox($settings) { + include plugin_dir_path( __FILE__ ) . 'admin/html/html-upgrade-nag.php'; + } + + /** * generate_rules_shipping_methods_html function. * @@ -126,15 +191,6 @@ class Shipping_by_Rules extends WC_Shipping_Method { } - /** - * Handle shipping rules settings - */ - public function process_shipping_rules_sorting() { - $ordering = isset($_POST[ 'rules_method_order']) ? array_map( 'wc_clean', $_POST[ 'rules_method_order'] ) : array(); - $this->helper->set_method_ordering($ordering); - } - - /** * calculate_shipping function. * @@ -143,25 +199,21 @@ class Shipping_by_Rules extends WC_Shipping_Method { * @return void */ public function calculate_shipping( $package = array()) { - $methods = $this->helper->get_rule_shipping_methods(); - foreach ($methods as $method) { + $rate = array( + 'id' => $this->get_rate_id(), + 'label' => $this->title, + 'cost' => 0, + 'package' => $package, + ); - $rates = $this->helper->getCosts($package, $method); - foreach ($rates as $r) { - $label = $r['name']; - if (isset($r['rulename']) && !empty($r['rulename'])) { - $label .= ' (' . $r['rulename'] . ')'; - } - $rate = array( - 'id' => $this->id . $r['method'], - 'label' => $label, - 'package' => $package, - 'cost' => $r['cost'], -// 'calc_tax' => 'per_item', - ); - // Register the rate - $this->add_rate( $rate ); + $rates = $this->helper->getCosts($package, $this); + foreach ($rates as $r) { + if (isset($r['rulename']) && !empty($r['rulename'])) { + $rate['label'] = $this->title . ' (' . $r['rulename'] . ')'; } + $rate['cost'] = $r['cost']; + $this->add_rate( $rate ); } + } } diff --git a/includes/rules_shipping_framework_woocommerce.php b/includes/rules_shipping_framework_woocommerce.php index b400a92..aeb05b6 100644 --- a/includes/rules_shipping_framework_woocommerce.php +++ b/includes/rules_shipping_framework_woocommerce.php @@ -95,22 +95,20 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { } protected function getMethodId($method) { - return $method->ID; + return $method->get_rate_id(); } protected function getMethodName($method) { - return $method->post_title; + return $method->title; } + // TODO: Legacy protected function parseMethodRules (&$method) { - $rulesets = Shipping_Rules_post_type::get_rulesets($method); - foreach ($rulesets as $ruleset) { - $this->parseMethodRule( - /* Rules */ isset($ruleset['rules'])?$ruleset['rules']:'', - /* Countries */isset($ruleset['countries'])?$ruleset['countries']:array(), - /* Rule info */array(), - /* Method */ $method); - } + return $this->parseMethodRule( + /* Rules */ isset($method->rules)?$method->rules:'', + /* Countries */array(), + /* Rule info */array(), + /* Method */ $method); } /** @@ -248,7 +246,6 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { // 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; @@ -267,7 +264,6 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { // The plugin provides its own function to retrieve the vendor for a product foreach ($products as $product) { $vendor = yith_get_vendor($product['data']->id, 'product'); -// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>"); if ($vendor->is_valid()) { $vendors[] = $vendor->slug; $vendornames[] = $vendor->name; @@ -448,30 +444,6 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { return $result; } - /** - * get_shipping_rules_methods function. - */ - static public function get_rule_shipping_methods() { - $unsortedmethods = get_posts (array ('posts_per_page' => '-1', 'post_type' => 'shipping_rules')); - $ordering = get_option( self::$_method_ordering, array() ); - $methods = array(); - foreach ($ordering as $o) { - foreach ($unsortedmethods as $key=>$m) { - if ($m->ID == $o) { - $methods[$o] = $m; - unset($unsortedmethods[$key]); - break; - } - } - } - $methods = $methods + $unsortedmethods; - return $methods; - } - - static public function set_method_ordering($ordering) { - update_option( self::$_method_ordering, $ordering ); - } - protected function createMethodRule ($r, $countries, $ruleinfo) { return new ShippingRule($this, $r, $countries, $ruleinfo); } diff --git a/legacy-includes/admin/html/html-shipping-methods.php b/legacy-includes/admin/html/html-shipping-methods.php new file mode 100644 index 0000000..a0eb924 --- /dev/null +++ b/legacy-includes/admin/html/html-shipping-methods.php @@ -0,0 +1,134 @@ +<?php + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} +$methods = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'shipping_rules', 'post_status' => array( 'draft', 'publish' ) ) ); + +?> +<tr valign="top"> + <th scope="row" class="titledesc"><?php echo $this->helper->__( 'Shipping By Rules Methods' ) ?></th> + <td class="forminp" id="<?php echo $this->id; ?>_rules_shipping_methods"> + + <table class="rules_shipping_methods widefat striped" cellspacing="0"> + <thead> + <tr> + <th class="name" ><?php echo $this->helper->__( 'Name' ); ?></th> + <th class="id" ><?php echo $this->helper->__( 'ID' ); ?></th> + <th class="status" ><?php echo $this->helper->__( 'Status' ); ?></th> + <th class="methods" ><?php echo $this->helper->__( 'Configured Rulesets' ); ?></th> + </tr> + </thead> + <tbody> + <?php + $i = 0; + foreach ( $methods as $method ) { + $alt = ''; +// $alt = ( $i++ ) % 2 == 0 ? 'alternate' : ''; + ?> + <tr> + <td class="name <?php echo $alt; ?>"> + <input type="hidden" name="rules_method_order[]" value="<?php echo esc_attr($method->ID); ?>" /> + <?php echo empty($method->post_title) ? $this->helper->__('Untitled Method') : esc_html($method->post_title); ?> + <div class='row-actions'> + <span class='edit'> + <a href='<?php echo get_edit_post_link( $method->ID ); ?>' title='<?php echo $this->helper->__( 'Edit Method'); ?>'> + <?php echo $this->helper->__('Edit'); ?> + </a> + | + </span> + <span class='trash'> + <a href='<?php echo get_delete_post_link( $method->ID ); ?>' title='<?php echo $this->helper->__('Delete Method'); ?>'><?php + echo $this->helper->__('Delete'); + ?></a> + </span> + </div> + </td> + <td class="id"> + <?php echo esc_html($method->ID); ?> + </td> + <td class="status"> + + <?php + if ( $method->post_status == 'publish' ) { ?> + <span class="status-enabled tips" data-tip="<?php echo __ ( 'Enabled', 'woocommerce' ); ?>"><?php echo __ ( 'Enabled', 'woocommerce' ); ?></span> + <?php + } else { + echo '-'; + } + ?> + + </td> + <td> + <?php + $rulesetnames = array(); + $rulesets = get_post_meta( $method->ID, '_rules_shipping_ruleset', true ); + if (!is_array($rulesets)) { + $rulesets = array(); + } + foreach ($rulesets as $ruleset) { + if (isset($ruleset['name']) && !empty($ruleset['name'])) { + $rulesetnames[] = $ruleset['name']; + } else { + $rulesetnames[] = $this->helper->__('<Unnamed>'); + } + } + if (!empty($rulesetnames)) { + echo esc_html(join(", ", $rulesetnames)); + } else { + echo $this->helper->__('<em>No rulesets defined</em>'); + } + ?> + </td> + </tr> + <?php + } + + if ( empty( $methods ) ) : + + ?><tr> + <td colspan='4'><?php echo $this->helper->__( 'There are no Shipping By Rules methods configured yet.' ); ?></td> + </tr><?php + endif; + + ?></tbody> + <tfoot> + <tr> + <th colspan='1' style='padding-left: 10px;'> + <a href='<?php echo admin_url( 'post-new.php?post_type=shipping_rules' ); ?>' class='add button'><?php echo $this->helper->__( 'Add Shipping By Rules method' ); ?></a> + </th> + <th colspan="3"> + <span class="description"><?php _e( 'Drag and drop the above shipping methods to control their display order.', 'woocommerce' ); ?></span> + </th> + </tr> + </tfoot> + </table> + <script type="text/javascript"> + jQuery(function() { + + // Sorting + jQuery('table.rules_shipping_methods tbody').sortable({ + items:'tr', + cursor:'move', + axis:'y', + handle: 'td', + scrollSensitivity:40, + helper:function(e,ui){ + ui.children().each(function(){ + jQuery(this).width(jQuery(this).width()); + }); +// ui.css('left', '0'); + return ui; + }, + start:function(event,ui){ + ui.item.css('background-color','#f6f6f6'); + }, + stop:function(event,ui){ + ui.item.removeAttr('style'); + } + }); + }); + </script> + </td> +</tr> +<?php diff --git a/legacy-includes/admin/html/html-upgrade-nag.php b/legacy-includes/admin/html/html-upgrade-nag.php new file mode 100644 index 0000000..c557306 --- /dev/null +++ b/legacy-includes/admin/html/html-upgrade-nag.php @@ -0,0 +1,28 @@ +<?php + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +?> + <div id="opentools-shippingbyrules-upgrade" class="rules_shipping rules_shipping_upgrade rules_shipping_meta_box rules_shipping_settings_meta_box postbox"> + <?php if (isset($settings['title'])) { ?><h3><?php echo esc_html($settings['title']); ?></h3><?php } ?> + <div class="contents"> + <div class="logoleft"><a href="<?php echo esc_html($settings['link']); ?>"><img src="<?php echo plugins_url('../../../assets/images/advlogo100.png', __FILE__); ?>"></a></div> + <!--p>Advanced features not included in the free plugin include:</p--> + <ul> + <li><b>Mathematical expressions</b>: shipping costs calculated from mathematical expressions (depending on weight, dimensions, amount, etc.): + <ul style="font-size: smaller"> + <li>Shipping costs per kg</li> + <li>Percentage shipping cost on the amount, etc.</li> + </ul> + <li><b>List functions</b>: conditions on certain products, categories, tags or shipping classes</li> + <li><b>Conditions for product subsets</b>: Conditions and shipping costs depending on values evaluated only for particular products, categories, tags or shipping classes + <li><b>Alphanumeric Postcodes</b>: Conditions on UK and Canadian postcodes</li> + <li><b>Coupon Codes</b>: conditions on coupon codes</li> + <li>...</li> + </ul> + <p>More information and purchase: <a class="button-primary" href="<?php echo esc_html($settings['link']); ?>" target="_blank">Get Support and advanced features</a></p> + </div> + </div> +<?php diff --git a/includes/admin/settings/meta-box-field-ruleset.php b/legacy-includes/admin/settings/meta-box-field-ruleset.php similarity index 100% rename from includes/admin/settings/meta-box-field-ruleset.php rename to legacy-includes/admin/settings/meta-box-field-ruleset.php diff --git a/legacy-includes/admin/settings/meta-box-help.php b/legacy-includes/admin/settings/meta-box-help.php new file mode 100644 index 0000000..80e53fa --- /dev/null +++ b/legacy-includes/admin/settings/meta-box-help.php @@ -0,0 +1,51 @@ +<?php +/** + * Shipping By Rules meta box Help. + * + * Display the help message / user guide for the Shipping by Rules Method. + * + * @author Reinhold Kainhofer + * @package OpenTools Shipping by Rules for WooCommerce + * @version 1.0.0 + */ + +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly + +?><div class='rules_shipping rules_shipping_help rules_shipping_meta_box rules_shipping_help_meta_box'> + <p>See also the the <a href='http://open-tools.net/documentation/advanced-shipping-by-rules-for-woocommerce.html'>Plugin's documentation</a> and <a href='http://open-tools.net/documentation/shipping-by-rules-plugins-for-virtuemart/rules-examples.html'>Rules Examples</a>.</p> + <ul class='otsr_list'> + <li>One rule per line, rule parts separated by Semicolon (;)</li> + <li>Rules are evaluated sequentially, first matching rule is offered</li> + <li>Typical form of a rule: + <blockquote> + Name="Rule name"; Amount<50; 1000<=ZIP<2000; Shipping=123 + </blockquote></li> + <li>Setting costs to NoShipping prevents method from offering any shipping</li> + <li>Conditions can contain <strong>comparison operators (<, <=, =<, ==, !=, <>, >=, =>, >)</strong>, variables and functions.</li> + <li>Some <strong>variables (case-insensitive)</strong>: + <ul> + <li><tt>Amount</tt>, <tt>Weight</tt>, <tt>ZIP</tt>, <tt>Products</tt> (number of products), <tt>Articles</tt> (counted with quantity), <tt>Volume</tt> (total volume of the order), <tt>Min/MaxVolume</tt>, <tt>Min/MaxLength</tt>, <tt>Min/MaxWidth</tt>, <tt>Min/MaxHeight</tt>, ....</li> + </ul> + </li> + <!--li>All rule parts of the form <strong><tt>[VARIABLE]=VALUE</tt> are assignments</strong>; allowed variables are + <ul> + <li><strong><tt>Name</tt></strong> (of the rule), </li> + <li><strong><tt>Shipping</tt></strong>, </li> + <li><strong><tt>ShippingWithTax</tt></strong>, </li> + <li><strong><tt>ExtraShippingCharge</tt></strong>, </li> + <li><strong><tt>ExtraShippingMultiplier</tt></strong>, </li> + <li><strong><tt>Condition</tt></strong>, </li> + <li><strong><tt>Variable</tt></strong>, </li> + <li><strong><tt>Value</tt></strong>, </li> + <li><strong><tt>Comment</tt></strong>.</li> + </ul> + The '<tt>Shipping='</tt> can be left out.</li--> + <li>In the <a href="http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html">advanced version</a>, all expressions may contain <strong>arbitrary basic arithmetic expressions (+, -, *, /, %, ^ and parentheses)</strong> of the above variables and functions like max(..), min(..), round(..), ceil(..), floor(..), day(), month(), etc..</li> + <li><strong>Alphanumeric postal codes</strong>: variables <tt>UK_Outward, UK_Area, UK_District, UK_Subdistrict, Canada_FSA, Canada_Area, Canada_Urban, Canada_Subarea, ZIP1, ZIP2, ZIP3, ZIP4, ZIP5</tt> and <tt>ZIP6</tt> in the <a href="http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html">advanced version</a>.</li> + </ul> + <p>EXAMPLE: A rule named 'Europe' that sets shipping costs of 5€ for orders weighing less than 5kg, 10€ for heavier orders, and free shipping from 100€ on would be:</p> + <blockquote><tt>Name=Free Shipping; 100<= Amount; 0<br/>Name=Europe; Weight<5; Shipping=5<br/>Name=Europe; Weight>=5; Shipping=10</tt></blockquote> + + +</div> +<?php \ No newline at end of file diff --git a/includes/admin/settings/meta-box-rulesets.php b/legacy-includes/admin/settings/meta-box-rulesets.php similarity index 100% rename from includes/admin/settings/meta-box-rulesets.php rename to legacy-includes/admin/settings/meta-box-rulesets.php diff --git a/includes/admin/settings/meta-box-settings.php b/legacy-includes/admin/settings/meta-box-settings.php similarity index 100% rename from includes/admin/settings/meta-box-settings.php rename to legacy-includes/admin/settings/meta-box-settings.php diff --git a/legacy-includes/legacy-rules-shipping-method.php b/legacy-includes/legacy-rules-shipping-method.php new file mode 100644 index 0000000..bc331ad --- /dev/null +++ b/legacy-includes/legacy-rules-shipping-method.php @@ -0,0 +1,184 @@ +<?php +/** + * Shipping By Rules Shipping Method + * http://open-tools.net/woocommerce/ + * Define Shipping cost by very general and flexible (text-based) rules. + * Ver. 1.0.0 + * Author: Open Tools, Reinhold Kainhofer + * License: GPLv3+ +*/ + +class Legacy_Shipping_by_Rules extends WC_Shipping_Method { + protected $helper = null; + /** + * Constructor for your shipping class + * + * @access public + * @return void + */ + public function __construct() { + if (class_exists("LegacyRulesShippingFrameworkWooCommerceAdvanced")) { + $this->helper = LegacyRulesShippingFrameworkWooCommerceAdvanced::getHelper(); + } else { + if (!class_exists("LegacyRulesShippingFrameworkWooCommerce")) { + require_once( plugin_dir_path( __FILE__ ) . 'legacy-rules_shipping_framework_woocommerce.php'); + } + $this->helper = LegacyRulesShippingFrameworkWooCommerce::getHelper(); + } + $this->id = 'legacy-shipping_by_rules'; // Id for your shipping method. Should be unique. + $this->title = $this->helper->__( 'Shipping By Rules (legacy)'); + $this->method_title = $this->helper->__( 'Shipping by Rules (legacy)' ); // Title shown in admin + $this->method_description = sprintf($this->helper->__('<strong>This method is deprecated in WooCommerce 2.6, where shipping zones are introduced, and will be removed in future versions.</strong> Please use WooCommerce\'s shipping zones for country restrictions and set up methods of type "Shipping by Rules" inside each shipping zone. Your existing rules and this legacy shipping method will continue to work until you manually transfer all rules to the <a href="%s">Shipping Zones</a>. and remove all Shipping by Rules methods here.'), admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); + $this->init(); + } + + public function setHelper($helper) { + $this->helper = $helper; + } + + /** + * Init your settings + * + * @access public + * @return void + */ + function init() { + $this->init_form_fields(); + $this->init_settings(); + + $this->enabled = $this->get_option ('enabled'); + + // Save settings in admin if you have any defined + add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); + add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_shipping_rules_sorting' ) ); + } + + /** + * Initialise Settings Form Fields + * + * @access public + * @return void + */ + public function init_form_fields() { + add_filter( 'woocommerce_admin_field_opentools_shippingbyrules_upgrade', array( &$this, 'admin_field_opentools_shippingbyrules_upgrade') ); + $fields = array_merge( + $this->helper->getUpgradeNagSettings(), + + array( + 'enabled' => array( + 'title' => __( 'Enable/Disable', 'woocommerce' ), + 'type' => 'checkbox', + 'label' => $this->helper->__( 'Enable Shipping By Rules'), + 'default' => 'yes' + ), + 'methods' => array( + 'type' => 'legacy_rules_shipping_methods', + ), + ) + ); + $this->form_fields = $fields; + } + + + public function getUpgradeNagSettings() { + $settings = array(); + if (!$this->isAdvanced()) { + $settings['opentools_shippingbyrules_upgrade'] = array( + 'name' => $this->__( 'Upgrade to the ADVANCED VERSION of the OpenTools Shipping by Rules plugin'), + 'type' => 'opentools_shippingbyrules_upgrade', + 'link' => 'http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html', + ); + } + return $settings; + } + + public function printUpgradeNagBox($settings) { + include plugin_dir_path( __FILE__ ) . 'admin/html/html-upgrade-nag.php'; + } + + /** + * generate_rules_shipping_methods_html function. + * + * @access public + * @return string + */ + public function generate_legacy_rules_shipping_methods_html() { + ob_start(); + include plugin_dir_path( __FILE__ ) . 'admin/html/html-shipping-methods.php'; + return ob_get_clean(); + } + + + /** + * validate_rules_shipping_methods_field function. + * Table does not need validation, so always return false. + * + * @access public + * @param mixed $key + * @return bool + */ + public function validate_legacy_rules_shipping_methods_field( $key ) { + return false; + } + + /** + * generate_rules_shipping_methods_html function. + * + * @access public + * @return string + */ + public function generate_opentools_shippingbyrules_upgrade_html($id, $settings) { + if (isset($settings['name'])) { + $settings['title'] = $settings['name']; + } + ob_start(); + ?> + <tr valign="top"> + <td colspan="2"> + <?php $this->helper->printUpgradeNagBox($settings); ?> + </td> + </tr> + <?php + return ob_get_clean(); + } + + + /** + * Handle shipping rules settings + */ + public function process_shipping_rules_sorting() { + $ordering = isset($_POST[ 'rules_method_order']) ? array_map( 'wc_clean', $_POST[ 'rules_method_order'] ) : array(); + $this->helper->set_method_ordering($ordering); + } + + + /** + * calculate_shipping function. + * + * @access public + * @param mixed $package + * @return void + */ + public function calculate_shipping( $package = array()) { + $methods = $this->helper->get_rule_shipping_methods(); + foreach ($methods as $method) { + + $rates = $this->helper->getCosts($package, $method); + foreach ($rates as $r) { + $label = $r['name']; + if (isset($r['rulename']) && !empty($r['rulename'])) { + $label .= ' (' . $r['rulename'] . ')'; + } + $rate = array( + 'id' => $this->id . $r['method'], + 'label' => $label, + 'package' => $package, + 'cost' => $r['cost'], +// 'calc_tax' => 'per_item', + ); + // Register the rate + $this->add_rate( $rate ); + } + } + } +} diff --git a/includes/rules-shipping-post-type.php b/legacy-includes/legacy-rules-shipping-post-type.php similarity index 99% rename from includes/rules-shipping-post-type.php rename to legacy-includes/legacy-rules-shipping-post-type.php index f4650b1..b026744 100644 --- a/includes/rules-shipping-post-type.php +++ b/legacy-includes/legacy-rules-shipping-post-type.php @@ -5,7 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly * * Initialize the Shipping by Rules post type (to configure the . * - * @class Shipping_Rules_post_type + * @class Legacy_Shipping_Rules_post_type * @author Reinhold Kainhofer * @package WooCommerce (Advanced) Shipping By Rules * @version 1.0.0 @@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly * (C) Jeroen Sormani, Licensed under the GPL V3+ */ -class Shipping_Rules_post_type { +class Legacy_Shipping_Rules_post_type { protected $helper = null; /** diff --git a/legacy-includes/legacy-rules_shipping_framework_woocommerce.php b/legacy-includes/legacy-rules_shipping_framework_woocommerce.php new file mode 100644 index 0000000..74c755c --- /dev/null +++ b/legacy-includes/legacy-rules_shipping_framework_woocommerce.php @@ -0,0 +1,90 @@ +<?php +/** + * Shipping by Rules generic helper class (WP/WooCommerce-specific) + * Reinhold Kainhofer, Open Tools, office@open-tools.net + * @copyright (C) 2012-2016 - Reinhold Kainhofer + * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html +**/ + +if ( !defined( 'ABSPATH' ) ) { + die( 'Direct Access to ' . basename( __FILE__ ) . ' is not allowed.' ); +} +require_once( plugin_dir_path( __FILE__ ) . '/../includes/rules_shipping_framework_woocommerce.php'); + +class LegacyRulesShippingFrameworkWooCommerce extends RulesShippingFrameworkWooCommerce { + protected static $_method_ordering = 'woocommerce_shipping_rules_ordering'; + + static function getHelper() { + static $helper = null; + if (!$helper) { + $helper = new LegacyRulesShippingFrameworkWooCommerce(); + $helper->setup(); + } + return $helper; + } + + protected function getMethodId($method) { + return $method->ID; + } + + protected function getMethodName($method) { + return $method->post_title; + } + + protected function parseMethodRules (&$method) { + $rulesets = Shipping_Rules_post_type::get_rulesets($method); + foreach ($rulesets as $ruleset) { + $this->parseMethodRule( + /* Rules */ isset($ruleset['rules'])?$ruleset['rules']:'', + /* Countries */isset($ruleset['countries'])?$ruleset['countries']:array(), + /* Rule info */array(), + /* Method */ $method); + } + } + + /** + * get_shipping_rules_methods function. + */ + static public function get_rule_shipping_methods() { + $unsortedmethods = get_posts (array ('posts_per_page' => '-1', 'post_type' => 'shipping_rules')); + $ordering = get_option( self::$_method_ordering, array() ); + $methods = array(); + foreach ($ordering as $o) { + foreach ($unsortedmethods as $key=>$m) { + if ($m->ID == $o) { + $methods[$o] = $m; + unset($unsortedmethods[$key]); + break; + } + } + } + $methods = $methods + $unsortedmethods; + return $methods; + } + + static public function set_method_ordering($ordering) { + update_option( self::$_method_ordering, $ordering ); + } + + protected function createMethodRule ($r, $countries, $ruleinfo) { + return new ShippingRule($this, $r, $countries, $ruleinfo); + } + + public function getUpgradeNagSettings() { + $settings = array(); + if (!$this->isAdvanced()) { + $settings['opentools_shippingbyrules_upgrade'] = array( + 'name' => $this->__( 'Upgrade to the ADVANCED VERSION of the OpenTools Shipping by Rules plugin'), + 'type' => 'opentools_shippingbyrules_upgrade', + 'link' => 'http://open-tools.net/woocommerce/advanced-shipping-by-rules-for-woocommerce.html', + ); + } + return $settings; + } + + public function printUpgradeNagBox($settings) { + include plugin_dir_path( __FILE__ ) . 'admin/html/html-upgrade-nag.php'; + } + + +} diff --git a/legacy-includes/legacy-rules_shipping_framework_woocommerce_advanced.php b/legacy-includes/legacy-rules_shipping_framework_woocommerce_advanced.php new file mode 100644 index 0000000..5ecda58 --- /dev/null +++ b/legacy-includes/legacy-rules_shipping_framework_woocommerce_advanced.php @@ -0,0 +1,52 @@ +<?php +/** + * Shipping by Rules generic helper class (WP/WooCommerce-specific) + * Reinhold Kainhofer, Open Tools, office@open-tools.net + * @copyright (C) 2012-2016 - Reinhold Kainhofer + * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html +**/ + +if ( !defined( 'ABSPATH' ) ) { + die( 'Direct Access to ' . basename( __FILE__ ) . ' is not allowed.' ); +} +if (!class_exists('LegacyRulesShippingFrameworkWooCommerce')) { + require_once( plugin_dir_path( __FILE__ ) . '/legacy-rules_shipping_framework_woocommerce.php'); +} + +class LegacyRulesShippingFrameworkWooCommerceAdvanced extends LegacyRulesShippingFrameworkWooCommerce { + + static function getHelper() { + static $helper = null; + if (!$helper) { + $helper = new LegacyRulesShippingFrameworkWooCommerceAdvanced(); + $helper->setup(); + } + return $helper; + } + function __construct() { + parent::__construct(); + } + function isAdvanced() { + return true; + } + protected function getOrderAddress ($cart, $method) { + $data = parent::getOrderAddress($cart, $method); + $address = $cart['destination']; + $zip = isset($address['postcode'])?trim($address['postcode']):''; + if (isset($zip) && $zip!='') { + $data = array_merge($data, $this->getAddressZIP($zip)); + } + return $data; + } + + protected function createMethodRule ($r, $countries, $ruleinfo) { + return new ShippingRule_Advanced($this, $r, $countries, $ruleinfo); + } + + protected function addCustomCartValues ($cart, $products, $method, &$values) { + $values['coupons'] = $cart['applied_coupons']; + return $values; + } + + +} diff --git a/legacy-woocommerce-advanced-shipping-by-rules.php b/legacy-woocommerce-advanced-shipping-by-rules.php new file mode 100644 index 0000000..9925eb0 --- /dev/null +++ b/legacy-woocommerce-advanced-shipping-by-rules.php @@ -0,0 +1,139 @@ +<?php +/** + * Copyright (C) 2015 Reinhold Kainhofer + * + * This file is part of WooCommerce Shipping By Rules, + * a plugin for WordPress and WooCommerce. + * + * WooCommerce Shipping By Rules is free software: + * You can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This software is distributed in the hope that + * it will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WordPress. If not, see <http://www.gnu.org/licenses/>. + */ + + +/** + * Class Legacy_WooCommerce_Shipping_By_Rules_Advanced. + * + * Main Shipping by Rules class (legacy version), add filters and handling all other files. + * + * @class Legacy_WooCommerce_Shipping_By_Rules_Advanced + * @author Reinhold Kainhofer + */ +class Legacy_WooCommerce_Shipping_By_Rules_Advanced { + public $version = '1.2.4'; + private static $instance; + + public function __construct() { + + if ( ! function_exists( 'is_plugin_active_for_network' ) ) + require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); + + // Check if WooCommerce is active + if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) : + if ( ! is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) : + return; + endif; + endif; + + $this->init(); + + } + + + public static function instance() { + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + return self::$instance; + } + + public function init() { + $this->hooks(); + $this->load_textdomain(); + $this->update(); + + if (!class_exists("LegacyRulesShippingFrameworkWooCommerceAdvanced")) { + require_once( plugin_dir_path( __FILE__ ) . 'legacy-includes/legacy-rules_shipping_framework_woocommerce_advanced.php'); + } + $this->helper = LegacyRulesShippingFrameworkWooCommerceAdvanced::getHelper(); + + // Shipping method post type definition: + if (!class_exists("Legacy_Shipping_Rules_post_type")) { + require_once plugin_dir_path( __FILE__ ) . 'legacy-includes/legacy-rules-shipping-post-type.php'; + } + $this->post_type = new Legacy_Shipping_Rules_post_type($this->helper); + add_filter( 'plugin_action_links_' . dirname(plugin_basename( __FILE__ )) . '/woocommerce-advanced-shipping-by-rules.php', array( &$this, 'shippingbyrules_add_settings_link' ) ); + } + + /** + * Add settings link to plugins page + */ + public function shippingbyrules_add_settings_link( $links ) { + $link = '<a href="admin.php?page=wc-settings&tab=shipping§ion=legacy-shipping_by_rules">'. $this->helper->__( 'Settings (legacy)' ) . '</a>'; + array_unshift( $links, $link ); + return $links; + } + + + public function update() { + + $db_version = get_option( 'shipping_by_rules_plugin_version', $this->version ); + + // Stop current version is up to date + if ( $db_version >= $this->version ) : + return; + endif; + + update_option( 'shipping_by_rules_plugin_version', $this->version ); + } + + public function hooks() { + add_action( 'woocommerce_shipping_init', array( $this, 'shipping_by_rules_init' ) ); + add_action( 'woocommerce_shipping_methods', array( $this, 'shipping_by_rules_add_shipping_method' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'shipping_by_rules_admin_enqueue_scripts' ) ); + } + + public function load_textdomain() { + // Load textdomain + load_plugin_textdomain('opentools-shippingrules', false, basename( dirname( __FILE__ ) ) . '/languages' ); + } + + public function shipping_by_rules_init() { + if (!class_exists('Legacy_Shipping_by_Rules')) { + require_once plugin_dir_path( __FILE__ ) . 'legacy-includes/legacy-rules-shipping-method.php'; + } + $this->rule_shipping_method = new Legacy_Shipping_by_Rules(); + $this->rule_shipping_method->setHelper($this->helper); + } + + public function shipping_by_rules_add_shipping_method( $methods ) { + if ( class_exists( 'Legacy_Shipping_by_Rules' ) ) : + $methods['legacy-shipping_by_rules'] = 'Legacy_Shipping_by_Rules'; + endif; + + return $methods; + } + + public function shipping_by_rules_admin_enqueue_scripts() { + // For some strange reason, WC does not define the select2.css style... + $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/'; + wp_enqueue_style( 'select2', $assets_path . 'css/select2.css' ); + + wp_enqueue_style( 'legacy_shipping_by_rules-style', plugins_url( 'assets/css/legacy-admin-styles.css', __FILE__ ), array('select2'), $this->version ); + wp_enqueue_style( 'shipping_by_rules-style', plugins_url( 'assets/css/admin-styles.css', __FILE__ ), array('select2'), $this->version ); + wp_enqueue_script( 'legacy-shipping-by-rules-config', plugins_url( 'assets/js/legacy-shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); + } + +} + +Legacy_WooCommerce_Shipping_By_Rules_Advanced::instance(); diff --git a/legacy-woocommerce-shipping-by-rules.php b/legacy-woocommerce-shipping-by-rules.php new file mode 100644 index 0000000..49878ff --- /dev/null +++ b/legacy-woocommerce-shipping-by-rules.php @@ -0,0 +1,137 @@ +<?php +/** + * Copyright (C) 2016 Reinhold Kainhofer + * + * This file is part of WooCommerce Shipping By Rules, + * a plugin for WordPress and WooCommerce. + * + * WooCommerce Shipping By Rules is free software: + * You can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This software is distributed in the hope that + * it will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WordPress. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * Class Legacy_WooCommerce_Shipping_By_Rules. + * + * Main Shipping by Rules class (legacy version), add filters and handling all other files. + * + * @class Legacy_WooCommerce_Shipping_By_Rules + * @author Reinhold Kainhofer + */ +class Legacy_WooCommerce_Shipping_By_Rules { + public $version = '1.2.4'; + private static $instance; + + public function __construct() { + if ( ! function_exists( 'is_plugin_active_for_network' ) ) + require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); + + // Check if WooCommerce is active + if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) : + if ( ! is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) : + return; + endif; + endif; + $this->init(); + } + + public static function instance() { + if ( is_null( self::$instance ) ) { + self::$instance = new self(); + } + return self::$instance; + } + + public function init() { + $this->hooks(); + $this->load_textdomain(); + $this->update(); + + if (!class_exists("LegacyRulesShippingFrameworkWooCommerce")) { + require_once( plugin_dir_path( __FILE__ ) . 'legacy-includes/legacy-rules_shipping_framework_woocommerce.php'); + } + $this->helper = LegacyRulesShippingFrameworkWooCommerce::getHelper(); + + // Shipping method post type definition: + if (!class_exists("Legacy_Shipping_Rules_post_type")) { + require_once plugin_dir_path( __FILE__ ) . 'legacy-includes/legacy-rules-shipping-post-type.php'; + } + $this->post_type = new Legacy_Shipping_Rules_post_type($this->helper); + add_filter( 'plugin_action_links_' . dirname(plugin_basename( __FILE__ )) . '/woocommerce-shipping-by-rules.php', array( &$this, 'shippingbyrules_add_settings_link' ) ); + } + + /** + * Add settings link to plugins page + */ + public function shippingbyrules_add_settings_link( $links ) { + $link = '<a href="admin.php?page=wc-settings&tab=shipping§ion=legacy-shipping_by_rules">'. $this->helper->__( 'Settings (legacy)' ) . '</a>'; + array_unshift( $links, $link ); + return $links; + } + + + public function update() { + $db_version = get_option( 'shipping_by_rules_plugin_version', $this->version ); + // Stop current version is up to date + if ( $db_version >= $this->version ) : + return; + endif; + // Update functions come here: + // From version 1.x.x to 1.x.y + // From version 1.x.y to 1.x.z + update_option( 'shipping_by_rules_plugin_version', $this->version ); + } + + public function hooks() { + add_action( 'woocommerce_shipping_init', array( $this, 'shipping_by_rules_init' ) ); + add_action( 'woocommerce_shipping_methods', array( $this, 'shipping_by_rules_add_shipping_method' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'shipping_by_rules_admin_enqueue_scripts' ) ); + } + + public function load_textdomain() { + load_plugin_textdomain('opentools-shippingrules', false, basename( dirname( __FILE__ ) ) . '/languages' ); + } + + public function shipping_by_rules_init() { + if (!class_exists('Legacy_Shipping_by_Rules')) { + require_once plugin_dir_path( __FILE__ ) . 'legacy-includes/legacy-rules-shipping-method.php'; + } + $this->rule_shipping_method = new Legacy_Shipping_by_Rules(); + } + + public function shipping_by_rules_add_shipping_method( $methods ) { + if ( class_exists( 'Legacy_Shipping_by_Rules' ) ) : + $methods['legacy-shipping_by_rules'] = 'Legacy_Shipping_by_Rules'; + endif; + // TODO: Figure out a way to add each shipping by rules method as a + // separate WooCommerce shipping method (ie. their order can be + // defined in the WC configuration and not only in the Shipping by + // Rules Method configuration screen. + return $methods; + } + + public function shipping_by_rules_admin_enqueue_scripts() { + // For some strange reason, WC does not define the select2.css style... + $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/'; + wp_enqueue_style( 'select2', $assets_path . 'css/select2.css' ); + + wp_enqueue_style( 'legacy_shipping_by_rules-style', plugins_url( 'assets/css/legacy-admin-styles.css', __FILE__ ), array('select2'), $this->version ); + wp_enqueue_style( 'shipping_by_rules-style', plugins_url( 'assets/css/admin-styles.css', __FILE__ ), array('select2'), $this->version ); + wp_enqueue_script( 'legacy-shipping-by-rules-config', plugins_url( 'assets/js/legacy-shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); + + } + + +} + +Legacy_WooCommerce_Shipping_By_Rules::instance(); diff --git a/readme-adv.txt b/readme-adv.txt index abf495b..0c32faf 100644 --- a/readme-adv.txt +++ b/readme-adv.txt @@ -3,7 +3,7 @@ Contributors: opentools Tags: WooCommerce, Shipment, Shipping Requires at least: 4.0 Tested up to: 4.5 -Stable tag: 1.2.5 +Stable tag: 1.3.0 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl.html diff --git a/readme.txt b/readme.txt index 97b12da..0382f71 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: opentools Tags: WooCommerce, Shipment, Shipping, Rules shipping Requires at least: 4.0 Tested up to: 4.5 -Stable tag: 1.2.5 +Stable tag: 1.3.0 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.3.0 = +* Convert the plugin to WooCommerce's shipping zones. Old methods will continue to work until they are removed. + = 1.2.5 = * Add variables username, first_name, last_name, email * Add list variable userroles (advanced version only) diff --git a/woocommerce-advanced-shipping-by-rules.php b/woocommerce-advanced-shipping-by-rules.php index 8378fb7..416cdb1 100644 --- a/woocommerce-advanced-shipping-by-rules.php +++ b/woocommerce-advanced-shipping-by-rules.php @@ -3,7 +3,7 @@ * 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.2.5 + * Version: 1.3.0 * Author: Open Tools, Reinhold Kainhofer * Author URI: http://open-tools.net * Text Domain: woocommerce-advanced-shipping-by-rules @@ -75,7 +75,7 @@ class WooCommerce_Shipping_By_Rules_Advanced { * @since 1.0.0 * @var string $version Plugin version number. */ - public $version = '1.2.5'; + public $version = '1.3.0'; /** @@ -146,11 +146,7 @@ class WooCommerce_Shipping_By_Rules_Advanced { $this->helper = RulesShippingFrameworkWooCommerceAdvanced::getHelper(); // Shipping method post type definition: - if (!class_exists("Shipping_Rules_post_type")) { - require_once plugin_dir_path( __FILE__ ) . 'includes/rules-shipping-post-type.php'; - } - $this->post_type = new Shipping_Rules_post_type($this->helper); - +// // Links to docs and config in the plugin page add_filter( 'plugin_row_meta', array( &$this, 'shippingbyrules_row_meta' ), 30, 2 ); add_filter( 'plugin_action_links_'.plugin_basename(__FILE__), array( &$this, 'shippingbyrules_add_settings_link' ) ); @@ -262,10 +258,7 @@ class WooCommerce_Shipping_By_Rules_Advanced { if ( class_exists( 'Shipping_by_Rules' ) ) : $methods['shipping_by_rules'] = 'Shipping_by_Rules'; endif; - // TODO: Figure out a way to add each shipping by rules method as a - // separate WooCommerce shipping method (ie. their order can be - // defined in the WC configuration and not only in the Shipping by - // Rules Method configuration screen. + return $methods; } @@ -282,32 +275,19 @@ class WooCommerce_Shipping_By_Rules_Advanced { $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/'; wp_enqueue_style( 'select2', $assets_path . 'css/select2.css' ); + wp_enqueue_style( 'legacy_shipping_by_rules-style', plugins_url( 'assets/css/legacy-admin-styles.css', __FILE__ ), array('select2'), $this->version ); wp_enqueue_style( 'shipping_by_rules-style', plugins_url( 'assets/css/admin-styles.css', __FILE__ ), array('select2'), $this->version ); - wp_enqueue_script( 'shipping-by-rules-config', plugins_url( 'assets/js/shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); + wp_enqueue_script( 'legacy-shipping-by-rules-config', plugins_url( 'assets/js/legacy-shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); } } +WooCommerce_Shipping_By_Rules_Advanced::instance(); -/** - * The main function responsible for returning the WooCommerce_Shipping_By_Rules_Advanced object. - * - * Use this function like you would a global variable, except without needing to declare the global. - * - * Example: <?php OpenTools_ShippingByRules()->method_name(); ?> - * - * @since 1.0.0 - * - * @return object WooCommerce_Shipping_By_Rules_Advanced class object. - */ -if ( ! function_exists( 'OpenTools_ShippingByRules_Advanced' ) ) : - - function OpenTools_ShippingByRules_Advanced() { - return WooCommerce_Shipping_By_Rules_Advanced::instance(); - } - -endif; - -OpenTools_ShippingByRules_Advanced(); +// Load the legacy plugin version IF REQUIRED! +$legacymethods = get_posts (array ('posts_per_page' => '-1', 'post_type' => 'shipping_rules')); +// if (count($legacymethods)>0) { + require_once( plugin_dir_path( __FILE__ ) . 'legacy-woocommerce-advanced-shipping-by-rules.php'); +// } diff --git a/woocommerce-shipping-by-rules.php b/woocommerce-shipping-by-rules.php index 56d2b0b..33aaf33 100644 --- a/woocommerce-shipping-by-rules.php +++ b/woocommerce-shipping-by-rules.php @@ -3,7 +3,7 @@ * 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.2.5 + * Version: 1.3.0 * Author: Open Tools, Reinhold Kainhofer * Author URI: http://open-tools.net * Text Domain: woocommerce-shipping-by-rules @@ -48,7 +48,7 @@ class WooCommerce_Shipping_By_Rules { * @since 1.0.0 * @var string $version Plugin version number. */ - public $version = '1.2.5'; + public $version = '1.3.0'; /** @@ -118,10 +118,11 @@ class WooCommerce_Shipping_By_Rules { $this->helper = RulesShippingFrameworkWooCommerce::getHelper(); // Shipping method post type definition: - if (!class_exists("Shipping_Rules_post_type")) { - require_once plugin_dir_path( __FILE__ ) . 'includes/rules-shipping-post-type.php'; - } - $this->post_type = new Shipping_Rules_post_type($this->helper); + // TODO: Legacy +// if (!class_exists("Shipping_Rules_post_type")) { +// // require_once plugin_dir_path( __FILE__ ) . 'includes/rules-shipping-post-type.php'; +// } +// $this->post_type = new Shipping_Rules_post_type($this->helper); // Links to docs and config in the plugin page add_filter( 'plugin_row_meta', array( &$this, 'shippingbyrules_row_meta' ), 30, 2 ); @@ -279,32 +280,19 @@ class WooCommerce_Shipping_By_Rules { $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/'; wp_enqueue_style( 'select2', $assets_path . 'css/select2.css' ); + wp_enqueue_style( 'legacy_shipping_by_rules-style', plugins_url( 'assets/css/legacy-admin-styles.css', __FILE__ ), array('select2'), $this->version ); wp_enqueue_style( 'shipping_by_rules-style', plugins_url( 'assets/css/admin-styles.css', __FILE__ ), array('select2'), $this->version ); - wp_enqueue_script( 'shipping-by-rules-config', plugins_url( 'assets/js/shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); + wp_enqueue_script( 'legacy-shipping-by-rules-config', plugins_url( 'assets/js/legacy-shipping-by-rules-config.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable', 'select2', 'wc-enhanced-select' ), $this->version, true ); } } +WooCommerce_Shipping_By_Rules::instance(); -/** - * The main function responsible for returning the WooCommerce_Shipping_By_Rules object. - * - * Use this function like you would a global variable, except without needing to declare the global. - * - * Example: <?php OpenTools_ShippingByRules()->method_name(); ?> - * - * @since 1.0.0 - * - * @return object WooCommerce_Shipping_By_Rules class object. - */ -if ( ! function_exists( 'OpenTools_ShippingByRules' ) ) : - - function OpenTools_ShippingByRules() { - return WooCommerce_Shipping_By_Rules::instance(); - } - -endif; - -OpenTools_ShippingByRules(); +// Load the legacy plugin version IF REQUIRED! +$legacymethods = get_posts (array ('posts_per_page' => '-1', 'post_type' => 'shipping_rules')); +if (count($legacymethods)>0) { + require_once( plugin_dir_path( __FILE__ ) . 'legacy-woocommerce-shipping-by-rules.php'); +} -- GitLab