zone tweaks

This commit is contained in:
Mike Jolley 2015-12-18 17:10:58 +00:00
parent f5bf764eec
commit 901db7b0f8
11 changed files with 100 additions and 54 deletions

View File

@ -138,7 +138,7 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
/**
* Called to calculate shipping rates for this method. Rates can be added using the add_rate() method.
*/
public function calculate_shipping() {}
public function calculate_shipping( $package = array() ) {}
/**
* Whether or not we need to calculate tax on top of the shipping rate.
@ -406,7 +406,7 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
* @return string
*/
public function get_instance_option_key() {
return $this->instance_id ? $this->plugin_id . $this->id . $this->instance_id . '_settings' : '';
return $this->instance_id ? $this->plugin_id . $this->id . '_' . $this->instance_id . '_settings' : '';
}
/**

View File

@ -25,7 +25,8 @@ class WC_Install {
'2.2.0' => 'updates/woocommerce-update-2.2.php',
'2.3.0' => 'updates/woocommerce-update-2.3.php',
'2.4.0' => 'updates/woocommerce-update-2.4.php',
'2.4.1' => 'updates/woocommerce-update-2.4.1.php'
'2.4.1' => 'updates/woocommerce-update-2.4.1.php',
'2.6.0' => 'updates/woocommerce-update-2.6.php'
);
/**

View File

@ -142,7 +142,7 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
* Called to calculate shipping rates for this method. Rates can be added using the add_rate() method.
* @uses WC_Shipping_Method::add_rate()
*/
public function calculate_shipping() {
public function calculate_shipping( $package = array() ) {
$this->add_rate( array(
'id' => $this->id . $this->instance_id,
'label' => $this->title,

View File

@ -206,7 +206,7 @@ class WC_Shipping_Legacy_Free_Shipping extends WC_Shipping_Method {
* calculate_shipping function.
* @return array
*/
public function calculate_shipping() {
public function calculate_shipping( $package = array() ) {
$args = array(
'id' => $this->id,
'label' => $this->title,

View File

@ -58,7 +58,7 @@ class WC_Shipping_Legacy_Local_Pickup extends WC_Shipping_Method {
/**
* calculate_shipping function.
*/
public function calculate_shipping() {
public function calculate_shipping( $package = array() ) {
$rate = array(
'id' => $this->id,
'label' => $this->title,

View File

@ -53,7 +53,7 @@ class WC_Shipping_Local_Pickup extends WC_Shipping_Method {
/**
* calculate_shipping function.
*/
public function calculate_shipping() {
public function calculate_shipping( $package = array() ) {
$this->add_rate( array(
'id' => $this->id . $this->instance_id,
'label' => $this->title,

View File

@ -0,0 +1,43 @@
<?php
/**
* Update WC to 2.6.0
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Updates
* @version 2.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $wpdb;
/**
* Old (table rate) shipping zones to new core shipping zones migration.
*
* zone_enabled and zone_type are no longer used, but it's safe to leave them be.
*/
if ( $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}woocommerce_shipping_zones` LIKE 'zone_enabled';" ) ) {
$wpdb->query( "ALTER TABLE {$wpdb->prefix}woocommerce_shipping_zones CHANGE `zone_type` `zone_type` VARCHAR(40) NOT NULL DEFAULT '';" );
$wpdb->query( "ALTER TABLE {$wpdb->prefix}woocommerce_shipping_zones CHANGE `zone_enabled` `zone_enabled` INT(1) NOT NULL DEFAULT 1;" );
}
/**
* Core uses woocommerce_shipping_zone_methods instead of woocommerce_shipping_zone_shipping_methods. Migrate the data.
*/
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_shipping_zone_shipping_methods';" ) ) {
$old_methods = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_shipping_zone_shipping_methods;" );
if ( $old_methods ) {
foreach ( $old_methods as $old_method ) {
$wpdb->insert( $wpdb->prefix . 'woocommerce_shipping_zone_methods', array(
'zone_id' => $old_method->zone_id,
'method_id' => $old_method->shipping_method_type,
'method_order' => $old_method->shipping_method_order
) );
$old_settings_key = 'woocommerce_' . $old_method->shipping_method_type . '-' . $old_method->shipping_method_id . '_settings';
add_option( 'woocommerce_' . $old_method->shipping_method_type . '_' . $wpdb->insert_id . '_settings', get_option( $old_settings_key ) );
}
}
}

View File

@ -339,25 +339,3 @@ function wc_get_checkout_url() {
return apply_filters( 'woocommerce_get_checkout_url', $checkout_url );
}
/**
* Register a shipping method.
*
* @since 1.5.7
* @param string|object $shipping_method class name (string) or a class object.
*/
function woocommerce_register_shipping_method( $shipping_method ) {
WC()->shipping->register_shipping_method( $shipping_method );
}
/**
* Get the shipping zone matching a given package from the cart.
*
* @since 2.6.0
* @uses WC_Shipping_Zones::get_zone_matching_package
* @param array $package
* @return WC_Shipping_Zone
*/
function wc_get_shipping_zone( $package ) {
return WC_Shipping_Zones::get_zone_matching_package( $package );
}

View File

@ -954,3 +954,25 @@ function wc_transaction_query( $type = 'start' ) {
}
}
}
/**
* Register a shipping method.
*
* @since 1.5.7
* @param string|object $shipping_method class name (string) or a class object.
*/
function woocommerce_register_shipping_method( $shipping_method ) {
WC()->shipping->register_shipping_method( $shipping_method );
}
/**
* Get the shipping zone matching a given package from the cart.
*
* @since 2.6.0
* @uses WC_Shipping_Zones::get_zone_matching_package
* @param array $package
* @return WC_Shipping_Zone
*/
function wc_get_shipping_zone( $package ) {
return WC_Shipping_Zones::get_zone_matching_package( $package );
}

View File

@ -752,31 +752,33 @@ function wc_sanitize_term_text_based( $term ) {
return trim( wp_unslash( strip_tags( $term ) ) );
}
/**
* Make numeric postcode.
*
* Converts letters to numbers so we can do a simple range check on postcodes.
* E.g. PE30 becomes 16050300 (P = 16, E = 05, 3 = 03, 0 = 00)
*
* @since 2.6.0
* @param string $postcode Regular postcode
* @return string
*/
function wc_make_numeric_postcode( $postcode ) {
$postcode_length = strlen( $postcode );
$letters_to_numbers = array_merge( array( 0 ), range( 'A', 'Z' ) );
$letters_to_numbers = array_flip( $letters_to_numbers );
$numeric_postcode = '';
if ( ! function_exists( 'wc_make_numeric_postcode' ) ) {
/**
* Make numeric postcode.
*
* Converts letters to numbers so we can do a simple range check on postcodes.
* E.g. PE30 becomes 16050300 (P = 16, E = 05, 3 = 03, 0 = 00)
*
* @since 2.6.0
* @param string $postcode Regular postcode
* @return string
*/
function wc_make_numeric_postcode( $postcode ) {
$postcode_length = strlen( $postcode );
$letters_to_numbers = array_merge( array( 0 ), range( 'A', 'Z' ) );
$letters_to_numbers = array_flip( $letters_to_numbers );
$numeric_postcode = '';
for ( $i = 0; $i < $postcode_length; $i ++ ) {
if ( is_numeric( $postcode[ $i ] ) ) {
$numeric_postcode .= str_pad( $postcode[ $i ], 2, '0', STR_PAD_LEFT );
} elseif ( isset( $letters_to_numbers[ $postcode[ $i ] ] ) ) {
$numeric_postcode .= str_pad( $letters_to_numbers[ $postcode[ $i ] ], 2, '0', STR_PAD_LEFT );
} else {
$numeric_postcode .= '00';
for ( $i = 0; $i < $postcode_length; $i ++ ) {
if ( is_numeric( $postcode[ $i ] ) ) {
$numeric_postcode .= str_pad( $postcode[ $i ], 2, '0', STR_PAD_LEFT );
} elseif ( isset( $letters_to_numbers[ $postcode[ $i ] ] ) ) {
$numeric_postcode .= str_pad( $letters_to_numbers[ $postcode[ $i ] ], 2, '0', STR_PAD_LEFT );
} else {
$numeric_postcode .= '00';
}
}
}
return $numeric_postcode;
return $numeric_postcode;
}
}

View File

@ -33,7 +33,7 @@ final class WooCommerce {
/**
* @var string
*/
public $version = '2.5.0';
public $version = '2.6.0';
/**
* @var WooCommerce The single instance of the class.