woocommerce/classes/shipping/shipping-free_shipping.php

120 lines
6.3 KiB
PHP
Raw Normal View History

2011-08-10 17:11:11 +00:00
<?php
/**
* Free Shipping Method
*
* A simple shipping method for free shipping
*
* @class free_shipping
* @package WooCommerce
* @category Shipping
* @author WooThemes
*/
class free_shipping extends woocommerce_shipping_method {
2011-09-06 11:18:22 +00:00
function __construct() {
2011-08-10 17:11:11 +00:00
$this->id = 'free_shipping';
2011-09-05 11:56:26 +00:00
$this->method_title = __('Free shipping', 'woothemes');
2011-08-10 17:11:11 +00:00
$this->enabled = get_option('woocommerce_free_shipping_enabled');
$this->title = get_option('woocommerce_free_shipping_title');
$this->min_amount = get_option('woocommerce_free_shipping_minimum_amount');
$this->availability = get_option('woocommerce_free_shipping_availability');
$this->countries = get_option('woocommerce_free_shipping_countries');
add_action('woocommerce_update_options', array(&$this, 'process_admin_options'));
add_option('woocommerce_free_shipping_availability', 'all');
add_option('woocommerce_free_shipping_title', 'Free Shipping');
}
2011-09-06 11:18:22 +00:00
function calculate_shipping() {
2011-08-10 17:11:11 +00:00
$this->shipping_total = 0;
$this->shipping_tax = 0;
$this->shipping_label = $this->title;
}
2011-09-06 11:18:22 +00:00
function admin_options() {
global $woocommerce;
2011-08-10 17:11:11 +00:00
?>
2011-08-13 13:57:48 +00:00
<h3><?php _e('Free Shipping', 'woothemes'); ?></h3>
<table class="form-table">
2011-08-19 20:11:04 +00:00
<tr valign="top">
2011-08-13 16:07:10 +00:00
<th scope="row" class="titledesc"><?php _e('Enable/disable', 'woothemes') ?></th>
2011-08-13 13:57:48 +00:00
<td class="forminp">
2011-08-13 16:07:10 +00:00
<fieldset><legend class="screen-reader-text"><span><?php _e('Enable/disable', 'woothemes') ?></span></legend>
2011-08-13 13:57:48 +00:00
<label for="woocommerce_free_shipping_enabled>">
<input name="woocommerce_free_shipping_enabled" id="woocommerce_free_shipping_enabled" type="checkbox" value="1" <?php checked(get_option('woocommerce_free_shipping_enabled'), 'yes'); ?> /> <?php _e('Enable Free Shipping', 'woothemes') ?></label><br>
</fieldset>
</td>
</tr>
2011-08-19 20:11:04 +00:00
<tr valign="top">
2011-08-13 13:57:48 +00:00
<th scope="row" class="titledesc"><?php _e('Method Title', 'woothemes') ?></th>
<td class="forminp">
<input type="text" name="woocommerce_free_shipping_title" id="woocommerce_free_shipping_title" style="min-width:50px;" value="<?php if ($value = get_option('woocommerce_free_shipping_title')) echo $value; else echo 'Free Shipping'; ?>" /> <span class="description"><?php _e('This controls the title which the user sees during checkout.', 'woothemes') ?></span>
</td>
</tr>
2011-08-19 20:11:04 +00:00
<tr valign="top">
2011-08-13 13:57:48 +00:00
<th scope="row" class="titledesc"><?php _e('Minimum Order Amount', 'woothemes') ?></th>
<td class="forminp">
<input type="text" name="woocommerce_free_shipping_minimum_amount" id="woocommerce_free_shipping_minimum_amount" style="min-width:50px;" value="<?php if ($value = get_option('woocommerce_free_shipping_minimum_amount')) echo $value; ?>" /> <span class="description"><?php _e('Users will need to spend this amount to get free shipping. Leave blank to disable.', 'woothemes') ?></span>
2011-08-13 13:57:48 +00:00
</td>
</tr>
2011-08-19 20:11:04 +00:00
<tr valign="top">
2011-08-13 13:57:48 +00:00
<th scope="row" class="titledesc"><?php _e('Method availability', 'woothemes') ?></th>
<td class="forminp">
<select name="woocommerce_free_shipping_availability" id="woocommerce_free_shipping_availability" style="min-width:100px;">
<option value="all" <?php if (get_option('woocommerce_free_shipping_availability') == 'all') echo 'selected="selected"'; ?>><?php _e('All allowed countries', 'woothemes'); ?></option>
<option value="specific" <?php if (get_option('woocommerce_free_shipping_availability') == 'specific') echo 'selected="selected"'; ?>><?php _e('Specific Countries', 'woothemes'); ?></option>
</select>
</td>
</tr>
<?php
$countries = $woocommerce->countries->countries;
2011-08-13 13:57:48 +00:00
$selections = get_option('woocommerce_free_shipping_countries', array());
?><tr class="multi_select_countries">
<th scope="row" class="titledesc"><?php _e('Specific Countries', 'woothemes'); ?></th>
<td class="forminp">
<div class="multi_select_countries"><ul><?php
if ($countries) foreach ($countries as $key=>$val) :
echo '<li><label><input type="checkbox" name="woocommerce_free_shipping_countries[]" value="'. $key .'" ';
if (in_array($key, $selections)) echo 'checked="checked"';
echo ' />'. __($val, 'woothemes') .'</label></li>';
endforeach;
?></ul></div>
</td>
</tr>
</table>
2011-08-10 17:11:11 +00:00
<script type="text/javascript">
jQuery(function() {
jQuery('select#woocommerce_free_shipping_availability').change(function(){
if (jQuery(this).val()=="specific") {
jQuery(this).parent().parent().next('tr.multi_select_countries').show();
} else {
jQuery(this).parent().parent().next('tr.multi_select_countries').hide();
}
}).change();
});
</script>
<?php
}
2011-09-06 11:18:22 +00:00
function process_admin_options() {
2011-08-10 17:11:11 +00:00
2011-08-13 13:57:48 +00:00
if(isset($_POST['woocommerce_free_shipping_enabled'])) update_option('woocommerce_free_shipping_enabled', 'yes'); else update_option('woocommerce_free_shipping_enabled', 'no');
2011-09-03 22:52:11 +00:00
if(isset($_POST['woocommerce_free_shipping_title'])) update_option('woocommerce_free_shipping_title', woocommerce_clean($_POST['woocommerce_free_shipping_title'])); else delete_option('woocommerce_free_shipping_title');
if(isset($_POST['woocommerce_free_shipping_minimum_amount'])) update_option('woocommerce_free_shipping_minimum_amount', woocommerce_clean($_POST['woocommerce_free_shipping_minimum_amount'])); else delete_option('woocommerce_free_shipping_minimum_amount');
if(isset($_POST['woocommerce_free_shipping_availability'])) update_option('woocommerce_free_shipping_availability', woocommerce_clean($_POST['woocommerce_free_shipping_availability'])); else delete_option('woocommerce_free_shipping_availability');
2011-08-10 17:11:11 +00:00
if (isset($_POST['woocommerce_free_shipping_countries'])) $selected_countries = $_POST['woocommerce_free_shipping_countries']; else $selected_countries = array();
update_option('woocommerce_free_shipping_countries', $selected_countries);
}
}
function add_free_shipping_method( $methods ) {
$methods[] = 'free_shipping'; return $methods;
}
add_filter('woocommerce_shipping_methods', 'add_free_shipping_method' );