FREESHIPPING
This commit is contained in:
parent
764341b228
commit
c4407d1b6f
|
@ -38,6 +38,9 @@ function woocommerce_coupon_data_meta_box($post) {
|
||||||
// Apply before tax
|
// Apply before tax
|
||||||
woocommerce_wp_checkbox( array( 'id' => 'apply_before_tax', 'label' => __('Apply coupon before tax?', 'woothemes'), 'description' => __('Check this box if the coupon should be applied before calculating a product\'s tax', 'woothemes') ) );
|
woocommerce_wp_checkbox( array( 'id' => 'apply_before_tax', 'label' => __('Apply coupon before tax?', 'woothemes'), 'description' => __('Check this box if the coupon should be applied before calculating a product\'s tax', 'woothemes') ) );
|
||||||
|
|
||||||
|
// Free Shipping
|
||||||
|
woocommerce_wp_checkbox( array( 'id' => 'free_shipping', 'label' => __('Enable free shipping', 'woothemes'), 'description' => sprintf(__('Check this box if the coupon enables free shipping (see <a href="%s">Free Shipping</a>)', 'woothemes'), admin_url('admin.php?page=woocommerce&tab=shipping_methods&subtab=shipping-free_shipping')) ) );
|
||||||
|
|
||||||
// Product ids
|
// Product ids
|
||||||
woocommerce_wp_text_input( array( 'id' => 'product_ids', 'label' => __('Product IDs', 'woothemes'), 'placeholder' => __('N/A', 'woothemes'), 'description' => __('(optional) Comma separate IDs which need to be in the cart to use this coupon or, for "Product Discounts", which products are discounted.', 'woothemes') ) );
|
woocommerce_wp_text_input( array( 'id' => 'product_ids', 'label' => __('Product IDs', 'woothemes'), 'placeholder' => __('N/A', 'woothemes'), 'description' => __('(optional) Comma separate IDs which need to be in the cart to use this coupon or, for "Product Discounts", which products are discounted.', 'woothemes') ) );
|
||||||
|
|
||||||
|
@ -78,6 +81,7 @@ function woocommerce_process_shop_coupon_meta( $post_id, $post ) {
|
||||||
$individual_use = isset($_POST['individual_use']) ? 'yes' : 'no';
|
$individual_use = isset($_POST['individual_use']) ? 'yes' : 'no';
|
||||||
$expiry_date = strip_tags(stripslashes( $_POST['expiry_date'] ));
|
$expiry_date = strip_tags(stripslashes( $_POST['expiry_date'] ));
|
||||||
$apply_before_tax = isset($_POST['apply_before_tax']) ? 'yes' : 'no';
|
$apply_before_tax = isset($_POST['apply_before_tax']) ? 'yes' : 'no';
|
||||||
|
$free_shipping = isset($_POST['free_shipping']) ? 'yes' : 'no';
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
update_post_meta( $post_id, 'discount_type', $type );
|
update_post_meta( $post_id, 'discount_type', $type );
|
||||||
|
@ -88,6 +92,7 @@ function woocommerce_process_shop_coupon_meta( $post_id, $post ) {
|
||||||
update_post_meta( $post_id, 'usage_limit', $usage_limit );
|
update_post_meta( $post_id, 'usage_limit', $usage_limit );
|
||||||
update_post_meta( $post_id, 'expiry_date', $expiry_date );
|
update_post_meta( $post_id, 'expiry_date', $expiry_date );
|
||||||
update_post_meta( $post_id, 'apply_before_tax', $apply_before_tax );
|
update_post_meta( $post_id, 'apply_before_tax', $apply_before_tax );
|
||||||
|
update_post_meta( $post_id, 'free_shipping', $free_shipping );
|
||||||
|
|
||||||
do_action('woocommerce_coupon_options');
|
do_action('woocommerce_coupon_options');
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ class woocommerce_coupon {
|
||||||
var $usage_count;
|
var $usage_count;
|
||||||
var $expiry_date;
|
var $expiry_date;
|
||||||
var $apply_before_tax;
|
var $apply_before_tax;
|
||||||
|
var $free_shipping;
|
||||||
|
|
||||||
/** get coupon with $code */
|
/** get coupon with $code */
|
||||||
function woocommerce_coupon( $code ) {
|
function woocommerce_coupon( $code ) {
|
||||||
|
@ -41,6 +42,7 @@ class woocommerce_coupon {
|
||||||
$this->usage_count = (int) get_post_meta($coupon->ID, 'usage_count', true);
|
$this->usage_count = (int) get_post_meta($coupon->ID, 'usage_count', true);
|
||||||
$this->expiry_date = ($expires = get_post_meta($coupon->ID, 'expiry_date', true)) ? strtotime($expires) : '';
|
$this->expiry_date = ($expires = get_post_meta($coupon->ID, 'expiry_date', true)) ? strtotime($expires) : '';
|
||||||
$this->apply_before_tax = get_post_meta($coupon->ID, 'apply_before_tax', true);
|
$this->apply_before_tax = get_post_meta($coupon->ID, 'apply_before_tax', true);
|
||||||
|
$this->free_shipping = get_post_meta($coupon->ID, 'free_shipping', true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -54,6 +56,10 @@ class woocommerce_coupon {
|
||||||
if ($this->apply_before_tax=='yes') return true; else return false;
|
if ($this->apply_before_tax=='yes') return true; else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enable_free_shipping() {
|
||||||
|
if ($this->free_shipping=='yes') return true; else return false;
|
||||||
|
}
|
||||||
|
|
||||||
/** Increase usage count */
|
/** Increase usage count */
|
||||||
function inc_usage_count() {
|
function inc_usage_count() {
|
||||||
$this->usage_count++;
|
$this->usage_count++;
|
||||||
|
|
|
@ -27,6 +27,7 @@ class free_shipping extends woocommerce_shipping_method {
|
||||||
$this->min_amount = $this->settings['min_amount'];
|
$this->min_amount = $this->settings['min_amount'];
|
||||||
$this->availability = $this->settings['availability'];
|
$this->availability = $this->settings['availability'];
|
||||||
$this->countries = $this->settings['countries'];
|
$this->countries = $this->settings['countries'];
|
||||||
|
$this->requires_coupon = $this->settings['requires_coupon'];
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
add_action('woocommerce_update_options_shipping_methods', array(&$this, 'process_admin_options'));
|
add_action('woocommerce_update_options_shipping_methods', array(&$this, 'process_admin_options'));
|
||||||
|
@ -57,6 +58,13 @@ class free_shipping extends woocommerce_shipping_method {
|
||||||
'description' => __('Users will need to spend this amount to get free shipping. Leave blank to disable.', 'woothemes'),
|
'description' => __('Users will need to spend this amount to get free shipping. Leave blank to disable.', 'woothemes'),
|
||||||
'default' => ''
|
'default' => ''
|
||||||
),
|
),
|
||||||
|
'requires_coupon' => array(
|
||||||
|
'title' => __( 'Coupon', 'woothemes' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'Free shipping requires a free shipping coupon', 'woothemes' ),
|
||||||
|
'description' => __('Users will need to enter a valid free shipping coupon code to use this method.', 'woothemes'),
|
||||||
|
'default' => 'no'
|
||||||
|
),
|
||||||
'availability' => array(
|
'availability' => array(
|
||||||
'title' => __( 'Method availability', 'woothemes' ),
|
'title' => __( 'Method availability', 'woothemes' ),
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
|
@ -100,6 +108,45 @@ class free_shipping extends woocommerce_shipping_method {
|
||||||
<?php
|
<?php
|
||||||
} // End admin_options()
|
} // End admin_options()
|
||||||
|
|
||||||
|
|
||||||
|
function is_available() {
|
||||||
|
global $woocommerce;
|
||||||
|
|
||||||
|
if ($this->enabled=="no") return false;
|
||||||
|
|
||||||
|
if (isset($woocommerce->cart->cart_contents_total) && isset($this->min_amount) && $this->min_amount && $this->min_amount > $woocommerce->cart->cart_contents_total) return false;
|
||||||
|
|
||||||
|
$ship_to_countries = '';
|
||||||
|
|
||||||
|
if ($this->availability == 'specific') :
|
||||||
|
$ship_to_countries = $this->countries;
|
||||||
|
else :
|
||||||
|
if (get_option('woocommerce_allowed_countries')=='specific') :
|
||||||
|
$ship_to_countries = get_option('woocommerce_specific_allowed_countries');
|
||||||
|
endif;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if (is_array($ship_to_countries)) :
|
||||||
|
if (!in_array($woocommerce->customer->get_shipping_country(), $ship_to_countries)) return false;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if ($this->requires_coupon=="yes") :
|
||||||
|
|
||||||
|
if ($woocommerce->cart->applied_coupons) : foreach ($woocommerce->cart->applied_coupons as $code) :
|
||||||
|
$coupon = &new woocommerce_coupon( $code );
|
||||||
|
|
||||||
|
if ( $coupon->enable_free_shipping() ) :
|
||||||
|
return true;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
endforeach; endif;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function calculate_shipping() {
|
function calculate_shipping() {
|
||||||
$this->shipping_total = 0;
|
$this->shipping_total = 0;
|
||||||
|
|
|
@ -112,6 +112,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
|
||||||
* Added dimensions to individual variations
|
* Added dimensions to individual variations
|
||||||
* Added settings API to be used by Shipping Methods and Payment Gateways
|
* Added settings API to be used by Shipping Methods and Payment Gateways
|
||||||
* Free shipping/Flat rate uses setting API
|
* Free shipping/Flat rate uses setting API
|
||||||
|
* Free shipping coupons
|
||||||
|
|
||||||
= 1.2.4 - 18/11/2011 =
|
= 1.2.4 - 18/11/2011 =
|
||||||
* More sale price logic fixes for variations. Now correctly compares variation's prices.
|
* More sale price logic fixes for variations. Now correctly compares variation's prices.
|
||||||
|
|
Loading…
Reference in New Issue