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

Convert the Shipping by Rules plugins to the new WC shipping zones. The old...

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.
parent ca1e8414
Branches
Tags
No related merge requests found
Showing
with 980 additions and 309 deletions
BASE=shipping-by-rules BASE=shipping-by-rules
PLATTFORM=woocommerce PLATTFORM=woocommerce
VENDOR=opentools VENDOR=opentools
VERSION=1.2.5 VERSION=1.3.0
DIR = $(shell pwd) DIR = $(shell pwd)
SVNDIR=wordpress-plugin-svn SVNDIR=wordpress-plugin-svn
......
table.rules_shipping_methods th { /*******************************/
padding-left: 10px; /* CSS for the Upgrade NAG Box */
} /*******************************/
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;
}
div#opentools-shippingbyrules-upgrade { div#opentools-shippingbyrules-upgrade {
padding: 5px 10px; padding: 5px 10px;
} }
div#opentools-shippingbyrules-upgrade.postbox { div#opentools-shippingbyrules-upgrade.postbox {
display: inline-block; 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 { div#opentools-shippingbyrules-upgrade ul {
list-style: disc; list-style: disc;
/* list-style-position: inside; */ /* list-style-position: inside; */
margin-left: 5px; margin-left: 5px;
padding-left: 5px; padding-left: 5px;
margin-top: 5px;
} }
div#opentools-shippingbyrules-upgrade li { div#opentools-shippingbyrules-upgrade li {
margin-left: 2em; margin-left: 2em;
...@@ -121,6 +36,12 @@ div#opentools-shippingbyrules-upgrade .logoleft { ...@@ -121,6 +36,12 @@ div#opentools-shippingbyrules-upgrade .logoleft {
div#opentools-shippingbyrules-upgrade .contents { div#opentools-shippingbyrules-upgrade .contents {
padding-left: 120px; padding-left: 120px;
} }
/*******************************/
/* CSS for the rules help Box */
/*******************************/
ul.otsr_list, ul.otsr_list ul { ul.otsr_list, ul.otsr_list ul {
list-style: disc; list-style: disc;
padding-left: 10px; padding-left: 10px;
...@@ -135,4 +56,17 @@ ul.otsr_list blockquote { ...@@ -135,4 +56,17 @@ ul.otsr_list blockquote {
background: #f0f0f0; background: #f0f0f0;
margin: 0; margin: 0;
padding: 0.2em 0.5em; 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
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;
}
...@@ -5,21 +5,27 @@ var showUpdateCredentialsRow = function (btn) { ...@@ -5,21 +5,27 @@ var showUpdateCredentialsRow = function (btn) {
var ajaxurl = jQuery(btn).data('ajaxurl'); var ajaxurl = jQuery(btn).data('ajaxurl');
var slug = jQuery(btn).data("slug"); var slug = jQuery(btn).data("slug");
var nonce = jQuery(btn).data("nonce"); var nonce = jQuery(btn).data("nonce");
var ajaxargs = {
type: "POST", var credentialRow = jQuery(btn).closest('table').find('tr#'+slug+'-credentials');
url: ajaxurl, if (credentialRow.length > 0) {
data: { jQuery(credentialRow).fadeOut(1000, function() { jQuery(this).remove(); });
action: 'getUpdateCredentialsRow_'+slug, } else {
slug: slug, var ajaxargs = {
_ajax_nonce: nonce type: "POST",
}, url: ajaxurl,
success: function ( json ) { data: {
jQuery(btn).closest('tr').after(json['row']); action: 'getUpdateCredentialsRow_'+slug,
}, slug: slug,
error: function() { }, _ajax_nonce: nonce
complete: function() { }, },
}; success: function ( json ) {
jQuery.ajax(ajaxargs); jQuery(btn).closest('tr').after(json['row']);
},
error: function() { },
complete: function() { },
};
jQuery.ajax(ajaxargs);
}
return false; return false;
}; };
......
...@@ -3,132 +3,70 @@ ...@@ -3,132 +3,70 @@
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
$methods = get_posts( array( 'posts_per_page' => '-1', 'post_type' => 'shipping_rules', 'post_status' => array( 'draft', 'publish' ) ) ); $methods = array();
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"><?php echo $this->helper->__( 'Shipping By Rules Methods' ) ?></th> <th colspan="2" scope="row" class="titledesc"><?php echo $this->helper->__( 'Configured Shipping By Rules Methods in all shipping zones' ) ?></th>
<td class="forminp" id="<?php echo $this->id; ?>_rules_shipping_methods"> </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> <thead>
<tr> <tr>
<th class="name" ><?php echo $this->helper->__( 'Name' ); ?></th> <th class="name" ><?php echo $this->helper->__( 'Zone name' ); ?></th>
<th class="id" ><?php echo $this->helper->__( 'ID' ); ?></th> <th class="methods" ><?php echo $this->helper->__( 'Configured Shipping by Rules methods' ); ?></th>
<th class="status" ><?php echo $this->helper->__( 'Status' ); ?></th> <th class="methods" ><?php echo $this->helper->__( 'Other methods' ); ?></th>
<th class="methods" ><?php echo $this->helper->__( 'Configured Rulesets' ); ?></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody class="wc-shipping-zone-rows">
<?php <?php
$i = 0; $zones = WC_Shipping_Zones::get_zones();
foreach ( $methods as $method ) { // get_zones does NOT include the global (fallback) zone => add it manually!
$alt = ''; $globalshippingzone = new WC_Shipping_Zone(0);
// $alt = ( $i++ ) % 2 == 0 ? 'alternate' : ''; $globalzone = $globalshippingzone->get_data();
?> $globalzone['formatted_zone_location'] = $globalshippingzone->get_formatted_location();
<tr> $globalzone['shipping_methods'] = $globalshippingzone->get_shipping_methods();
<td class="name <?php echo $alt; ?>"> $zones[] = $globalzone;
<input type="hidden" name="rules_method_order[]" value="<?php echo esc_attr($method->ID); ?>" /> foreach ($zones as $zone) {
<?php echo empty($method->post_title) ? $this->helper->__('Untitled Method') : esc_html($method->post_title); ?> ?>
<div class='row-actions'> <tr>
<span class='edit'> <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>
<a href='<?php echo get_edit_post_link( $method->ID ); ?>' title='<?php echo $this->helper->__( 'Edit Method'); ?>'> <td class="methods wc-shipping-zone-methods ">
<?php echo $this->helper->__('Edit'); ?> <ul>
</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 <?php
} else { foreach ($zone['shipping_methods'] as $method) {
echo '-'; 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> <td class="methods wc-shipping-zone-methods ">
<ul>
<?php <?php
$rulesetnames = array(); foreach ($zone['shipping_methods'] as $method) {
$rulesets = get_post_meta( $method->ID, '_rules_shipping_ruleset', true ); if ($method->id != 'shipping_by_rules') {
if (!is_array($rulesets)) { $methodclass = ($method->enabled=='no')?'method_disabled':'method_enabled';
$rulesets = array(); ?>
<li class="<?php echo $methodclass;?>"><?php echo $method->title; ?></li>
<?php
} }
foreach ($rulesets as $ruleset) { } ?>
if (isset($ruleset['name']) && !empty($ruleset['name'])) { </ul>
$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> </td>
</tr> </tr>
<?php <?php
} } ?>
</tbody>
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> </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> </td>
</tr> </tr>
<?php <?php
...@@ -11,16 +11,14 @@ if ( ! defined( 'ABSPATH' ) ) { ...@@ -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> <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--> <!--p>Advanced features not included in the free plugin include:</p-->
<ul> <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"> <ul style="font-size: smaller">
<li>Shipping costs per kg</li> <li>Shipping costs per kg</li>
<li>Percentage shipping cost on the amount, etc.</li> <li>Percentage shipping cost on the amount, etc.</li>
</ul> </ul>
<li><b>List functions</b>: conditions on certain products, categories, tags or shipping classes</li> <li><b>Conditions for product subsets</b>: Conditions / costs depending on particular products, categories, tags or shipping classes
<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>Alphanumeric Postcodes</b>: Conditions on UK and Canadian postcodes</li>
<li><b>Coupon Codes</b>: conditions on coupon codes</li> <li><b>Coupon Codes</b>: conditions on coupon codes</li>
<li>...</li>
</ul> </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> <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>
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
* License: GPLv3+ * License: GPLv3+
*/ */
if (!defined('ABSPATH')) {
exit;
}
class Shipping_by_Rules extends WC_Shipping_Method { class Shipping_by_Rules extends WC_Shipping_Method {
protected $helper = null; protected $helper = null;
/** /**
...@@ -16,7 +20,7 @@ class Shipping_by_Rules extends WC_Shipping_Method { ...@@ -16,7 +20,7 @@ class Shipping_by_Rules extends WC_Shipping_Method {
* @access public * @access public
* @return void * @return void
*/ */
public function __construct() { public function __construct($instance_id = 0) {
if (class_exists("RulesShippingFrameworkWooCommerceAdvanced")) { if (class_exists("RulesShippingFrameworkWooCommerceAdvanced")) {
$this->helper = RulesShippingFrameworkWooCommerceAdvanced::getHelper(); $this->helper = RulesShippingFrameworkWooCommerceAdvanced::getHelper();
} else { } else {
...@@ -26,9 +30,14 @@ class Shipping_by_Rules extends WC_Shipping_Method { ...@@ -26,9 +30,14 @@ class Shipping_by_Rules extends WC_Shipping_Method {
$this->helper = RulesShippingFrameworkWooCommerce::getHelper(); $this->helper = RulesShippingFrameworkWooCommerce::getHelper();
} }
$this->id = 'shipping_by_rules'; // Id for your shipping method. Should be unique. $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_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->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(); $this->init();
} }
...@@ -44,39 +53,76 @@ class Shipping_by_Rules extends WC_Shipping_Method { ...@@ -44,39 +53,76 @@ class Shipping_by_Rules extends WC_Shipping_Method {
* @return void * @return void
*/ */
function init() { 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_form_fields();
$this->init_settings(); $this->init_settings();
$this->enabled = $this->get_option ('enabled');
// Save settings in admin if you have any defined // 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_admin_options' ) );
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_shipping_rules_sorting' ) );
} }
/** function define_global_form_fields() {
* Initialise Settings Form Fields return array_merge(
*
* @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(), $this->helper->getUpgradeNagSettings(),
array( array(
'enabled' => array( /* 'debug' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ), 'title' => $this->helper->__('Enable debug messages'),
'type' => 'checkbox', 'type' => 'checkbox',
'label' => $this->helper->__( 'Enable Shipping By Rules'), 'label' => $this->helper->__('If enabled and WP_DEBUG is set, all defined variables and their values are printed into the WordPress debug log.' ),
'default' => 'yes' '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( 'methods' => array(
'type' => 'rules_shipping_methods', '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 { ...@@ -104,6 +150,25 @@ class Shipping_by_Rules extends WC_Shipping_Method {
return false; 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. * generate_rules_shipping_methods_html function.
* *
...@@ -126,15 +191,6 @@ class Shipping_by_Rules extends WC_Shipping_Method { ...@@ -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. * calculate_shipping function.
* *
...@@ -143,25 +199,21 @@ class Shipping_by_Rules extends WC_Shipping_Method { ...@@ -143,25 +199,21 @@ class Shipping_by_Rules extends WC_Shipping_Method {
* @return void * @return void
*/ */
public function calculate_shipping( $package = array()) { public function calculate_shipping( $package = array()) {
$methods = $this->helper->get_rule_shipping_methods(); $rate = array(
foreach ($methods as $method) { 'id' => $this->get_rate_id(),
'label' => $this->title,
'cost' => 0,
'package' => $package,
);
$rates = $this->helper->getCosts($package, $method); $rates = $this->helper->getCosts($package, $this);
foreach ($rates as $r) { foreach ($rates as $r) {
$label = $r['name']; if (isset($r['rulename']) && !empty($r['rulename'])) {
if (isset($r['rulename']) && !empty($r['rulename'])) { $rate['label'] = $this->title . ' (' . $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 );
} }
$rate['cost'] = $r['cost'];
$this->add_rate( $rate );
} }
} }
} }
...@@ -95,22 +95,20 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { ...@@ -95,22 +95,20 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework {
} }
protected function getMethodId($method) { protected function getMethodId($method) {
return $method->ID; return $method->get_rate_id();
} }
protected function getMethodName($method) { protected function getMethodName($method) {
return $method->post_title; return $method->title;
} }
// TODO: Legacy
protected function parseMethodRules (&$method) { protected function parseMethodRules (&$method) {
$rulesets = Shipping_Rules_post_type::get_rulesets($method); return $this->parseMethodRule(
foreach ($rulesets as $ruleset) { /* Rules */ isset($method->rules)?$method->rules:'',
$this->parseMethodRule( /* Countries */array(),
/* Rules */ isset($ruleset['rules'])?$ruleset['rules']:'', /* Rule info */array(),
/* Countries */isset($ruleset['countries'])?$ruleset['countries']:array(), /* Method */ $method);
/* Rule info */array(),
/* Method */ $method);
}
} }
/** /**
...@@ -248,7 +246,6 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { ...@@ -248,7 +246,6 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework {
// The plugin provides its own function to retrieve the vendor for a product // The plugin provides its own function to retrieve the vendor for a product
foreach ($products as $product) { foreach ($products as $product) {
foreach (get_product_vendors($product['data']->id) as $vendor) { foreach (get_product_vendors($product['data']->id) as $vendor) {
// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>");
$vendors[] = $vendor->slug; $vendors[] = $vendor->slug;
$vendornames[] = $vendor->title; $vendornames[] = $vendor->title;
$vendorids[] = $vendor->ID; $vendorids[] = $vendor->ID;
...@@ -267,7 +264,6 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { ...@@ -267,7 +264,6 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework {
// The plugin provides its own function to retrieve the vendor for a product // The plugin provides its own function to retrieve the vendor for a product
foreach ($products as $product) { foreach ($products as $product) {
$vendor = yith_get_vendor($product['data']->id, 'product'); $vendor = yith_get_vendor($product['data']->id, 'product');
// $this->printWarning("<pre>vendor: ".print_r($vendor,1)."</pre>");
if ($vendor->is_valid()) { if ($vendor->is_valid()) {
$vendors[] = $vendor->slug; $vendors[] = $vendor->slug;
$vendornames[] = $vendor->name; $vendornames[] = $vendor->name;
...@@ -448,30 +444,6 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { ...@@ -448,30 +444,6 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework {
return $result; 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) { protected function createMethodRule ($r, $countries, $ruleinfo) {
return new ShippingRule($this, $r, $countries, $ruleinfo); return new ShippingRule($this, $r, $countries, $ruleinfo);
} }
......
<?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
<?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
<?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&lt;50; 1000&lt;=ZIP&lt;2000; Shipping=123
</blockquote></li>
<li>Setting costs to NoShipping prevents method from offering any shipping</li>
<li>Conditions can contain <strong>comparison operators (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</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&lt;= Amount; 0<br/>Name=Europe; Weight&lt;5; Shipping=5<br/>Name=Europe; Weight>=5; Shipping=10</tt></blockquote>
</div>
<?php
\ No newline at end of file
<?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 );
}
}
}
}
...@@ -5,7 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ...@@ -5,7 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
* *
* Initialize the Shipping by Rules post type (to configure the . * Initialize the Shipping by Rules post type (to configure the .
* *
* @class Shipping_Rules_post_type * @class Legacy_Shipping_Rules_post_type
* @author Reinhold Kainhofer * @author Reinhold Kainhofer
* @package WooCommerce (Advanced) Shipping By Rules * @package WooCommerce (Advanced) Shipping By Rules
* @version 1.0.0 * @version 1.0.0
...@@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ...@@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
* (C) Jeroen Sormani, Licensed under the GPL V3+ * (C) Jeroen Sormani, Licensed under the GPL V3+
*/ */
class Shipping_Rules_post_type { class Legacy_Shipping_Rules_post_type {
protected $helper = null; protected $helper = null;
/** /**
......
<?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';
}
}
<?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;
}
}
<?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&section=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();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment