WordPress.org

Plugin Directory

Changeset 1659385


Ignore:
Timestamp:
05/17/17 12:52:32 (10 days ago)
Author:
bobbingwide
Message:

v0.1.0 - Now supports local currency format and HTML in the shipping method title override. Tested with WordPress 4.7.5, WooCommerce 3.0 and PHP 7.1

Location:
oik-weight-zone-shipping/trunk
Files:
2 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • oik-weight-zone-shipping/trunk/class-oik-weight-zone-shipping.php

    r1630308 r1659385  
    1 <?php // (C) Copyright Bobbing Wide 2015,2016 
     1<?php // (C) Copyright Bobbing Wide 2015-2017 
    22 
    33/** 
    4  * Single rate weight zone shipping class WooCommerce Extension 
     4 * Single rate weight zone shipping class WooCommerce extension 
    55 * 
    66 * Implements single rate shipping charges by weight and shipping zone 
    7  * Depends on WooCommerce 2.6 or higher 
     7 * Depends on WooCommerce 2.6, 3.0 or higher 
    88 *   
    99 */ 
     
    1717     */ 
    1818    public $shippingrate_title; 
     19     
     20    /** 
     21     * We no longer allow a '/' in the localized version. 
     22     * But it's supported in the original 'options' field. 
     23     */ 
     24    private $allowed_delimiters = array( "|", "," ); 
     25    private $dot_rate_delimiters = array( "|", "/", "," ); 
     26    private $decimal_separator; 
     27    private $thousand_separator;  
     28    private $decimals; 
     29     
     30    private $delimiters = null; 
    1931   
    2032    /** 
     
    3446    function __construct( $instance_id = 0 ) { 
    3547        parent::__construct( $instance_id ); 
    36         bw_trace2( ); 
     48        //bw_trace2( ); 
     49        //bw_backtrace(); 
    3750        $this->supports = array( "shipping-zones", "instance-settings", "instance-settings-modal" ); 
    3851        $this->id = 'oik_weight_zone_shipping';  
     
    5467     */ 
    5568    function init() { 
     69     
     70        $this->set_allowed_delimiters(); 
    5671        $this->init_form_fields(); 
    5772        $this->init_settings(); 
     73        $this->init_instance_settings(); 
     74        //bw_trace2( $this->instance_settings, "instance_settings" ); 
     75        $this->convert_rates_to_display(); 
    5876 
    5977        $this->enabled          = $this->get_option('enabled'); 
    60         //$this->title            = $this->get_option('title'); 
    61         //$this->availability     = 'specific'; 
    6278         
    63         //$this->country_group_no   = $this->get_option('country_group_no'); 
    64         //$this->countries      = $this->get_option('countries'); 
    6579        $this->type             = 'order'; 
    6680        $this->tax_status       = $this->get_option('tax_status'); 
    6781        $this->fee              = $this->get_option('fee'); 
    6882         
    69         // We now deal with instance_options using $this->get_option( "options" ); 
    70         //   
    71         //$this->options            = isset( $this->settings['options'] ) ? $this->settings['options'] : ''; 
    72         //$this->options            = (array) explode( "\n", $this->options ); 
     83        //bw_trace2( $this->fee, "this->fee" ); 
     84        $this->instance_settings['fee'] = $this->price( $this->fee ); 
     85         
    7386         
    7487        // @TODO What do we do with regards to availability 
     88        //$this->availability     = 'specific'; 
    7589        //if ( empty( $this->countries ) ) { 
    7690        //  $this->availability = $this->settings['availability'] = 'all'; 
    7791        //} 
    7892         
    79         $this->title                = $this->get_option( 'title' ); 
    80         //$this->tax_status           = $this->get_option( 'tax_status' ); 
    81         //$this->cost                 = $this->get_option( 'cost' ); 
    82         //$this->type                 = $this->get_option( 'type', 'class' ); 
     93        $this->title              = $this->get_option( 'title' ); 
    8394        $this->shippingrate_title = $this->title; 
    8495    } 
    85      
     96 
    8697    /** 
    8798     * Set the instance form fields 
     
    92103     */  
    93104    function init_form_fields() { 
     105        $six_ninety_five = $this->price( 6.95 );  
     106        $three_fifty = $this->price( 3.50 ); 
    94107        $this->instance_form_fields = array( 
    95108                'title'      => array( 
     
    99112                    'default'     => __( 'Weight zone shipping', 'oik-weight-zone-shipping' ), 
    100113                    'desc_tip'    => true, 
    101  
    102114                ), 
    103                 'options'       => array( 
     115                'rates'       => array( 
    104116                    'title'       => __( 'Shipping Rates', 'oik-weight-zone-shipping' ), 
    105117                    'type'        => 'textarea', 
    106                     'description' => sprintf( __( 'Set your weight based rates in %1$s for this shipping zone (one per line).<br /> Format: Max weight|Cost|Method Title override<br />Example: 10|6.95|Standard rate <br />For decimal, use a dot not a comma.', 'oik-weight-zone-shipping' ),  get_option( 'woocommerce_weight_unit' ) ), 
     118                    'description' => sprintf( __( 'Set your weight based rates in %1$s for this shipping zone (one per line).<br /> Format: Max weight | Cost | Method Title override<br />Example: 10 | %2$s | Standard rate', 'oik-weight-zone-shipping' ),  get_option( 'woocommerce_weight_unit' ), $six_ninety_five ), 
    107119                    'default'     => '', 
    108120                    'desc_tip'    => false, 
    109                     'placeholder'   => 'max weight | cost | Method title override', 
     121                    'placeholder'   => __( 'Max weight | Cost | Method Title override', 'oik-weight-zone-shipping' ), 
    110122                ), 
    111123                'tax_status' => array( 
     
    120132                        ) 
    121133                ), 
    122                  
    123134                'fee'        => array( 
    124135                    'title'       => __( 'Handling Fee', 'oik-weight-zone-shipping' ), 
    125136                    'type'        => 'text', 
    126                     'description' => __( 'Fee excluding tax, e.g. 3.50. Leave blank to disable.', 'oik-weight-zone-shipping' ), 
     137                    'description' => sprintf( __( 'Fee excluding tax, e.g. %1$s. Leave blank to disable.', 'oik-weight-zone-shipping' ), $three_fifty ), 
    127138                    'default'     => '', 
    128139                    'desc_tip'      => true, 
     
    130141        ); 
    131142    } 
    132      
     143 
    133144    /** 
    134145     * Return if the method is available 
    135      */ 
    136      
     146     * 
     147     * @return bool true  
     148     */ 
    137149    function is_available( $package ) { 
    138         bw_trace2(); 
    139         return( true ); 
     150        //bw_trace2(); 
     151        return true; 
    140152    } 
    141153 
     
    173185        } 
    174186    } 
     187     
     188    /** 
     189     * Gets the rate array field from a rates display line using user defined delimiters 
     190     * 
     191     * @param string $value 
     192     * @param array $allowed_delimiters for the field separator 
     193     * @return array rate; 0=> max weight, 1=> rate, 2=> label 
     194     */ 
     195    function get_local_rate( $value, $allowed_delimiters ) { 
     196        $value = trim( $value ); 
     197        $value = str_replace( $allowed_delimiters, "|", $value ); 
     198        $rate = explode( "|", $value ); 
     199        foreach ( $rate as $key => $val ) { 
     200            $rate[$key] = trim( $val ); 
     201        } 
     202        if ( !isset( $rate[0] ) ) { 
     203            $rate[0] = null; 
     204        }   else { 
     205            $rate[0] = $this->get_value_as_decimal( $rate[0] ); 
     206        } 
     207        if ( !isset( $rate[1] ) ) { 
     208            $rate[1] = null; 
     209        }   else { 
     210            $rate[1] = $this->get_value_as_decimal( $rate[1] ); 
     211        } 
     212        if ( !isset( $rate[2] ) ) { 
     213            $rate[2] = null; 
     214        } 
     215        return $rate; 
     216    } 
     217 
     218    /** 
     219     * Returns a decimal price value 
     220     *  
     221     * The number may have been entered using the thousand and decimal separators currently specified. 
     222     * OR the user could simply have used '.'s 
     223     *  
     224     * - We want to convert the incoming number to a simple decimal value. 
     225     * - We assume that the separator character are sensible. 
     226     * - We don't care how many decimal places are used on input 
     227     *  
     228     * e.g. 
     229     * Thous | Dec  | Value     | Return 
     230     * ----- | ---  | --------- | ------- 
     231     * ,     | .    | 1,234.56  | 1234.56 
     232     * .     | ,    | 1.234,56  | 1234.56 
     233     * blank | ,    | 1 234,56  | 1234.56 
     234     * xy    | z    | 1xy234z56 | 1234.56  
     235     *   
     236     * @param string $value 
     237     * @return string decimal value 
     238     */ 
     239    function get_value_as_decimal( $value ) { 
     240        $value = str_replace( $this->thousand_separator, "", $value ); 
     241        $value = str_replace( $this->decimal_separator, ".", $value ); 
     242        return $value; 
     243    } 
     244 
     245    /** 
     246     * Get the useable rate 
     247     * 
     248     * @param string $value 
     249     * @return array $rate_array  
     250     */ 
     251    function get_rate( $value ) { 
     252        $rate_array = $this->get_local_rate( $value, $this->delimiters ); 
     253        //bw_trace2( $rate_array, "rate array", true ); 
     254        return $rate_array; 
     255    } 
     256 
     257    /**  
     258     * Sets the allowed field delimiters 
     259     *  
     260     * We remove any delimiters that are defined as WooCommerce currency separators 
     261     *  
     262     * Notes:  
     263     * - Default separator for decimal is a dot aka period '.' 
     264     * - Default separator for thousand is ',' 
     265     * - WooCommerce allows the separators to be the same value. We don't. 
     266     * - Separators can also be blank, or null. 
     267     * - We don't allow '|' to be used as a currency separator. 
     268     * - Do we really expect rates to be in the thousands? 
     269     * - We'll allow the weight to be entered using the same rules as currency 
     270     */ 
     271    function set_allowed_delimiters( ) { 
     272        //$this->allowed_delimiters = array( "/", "," ); 
     273        $this->decimal_separator = wc_get_price_decimal_separator(); 
     274        $this->thousand_separator = wc_get_price_thousand_separator(); 
     275        $this->decimals = wc_get_price_decimals(); 
     276        $acceptable = $this->acceptable_separators(); 
     277         
     278        $allowed_delimiters = array_diff( $this->allowed_delimiters, array( $this->decimal_separator, $this->thousand_separator ) ); 
     279        //bw_trace2( $allowed_delimiters, "allowed delimiters" ); 
     280        $this->allowed_delimiters = $allowed_delimiters; 
     281        return $acceptable; 
     282    } 
     283 
     284    /** 
     285     * Tests separators are acceptable 
     286     * 
     287     * WooCommerce 3.0 doesn't perform any sanity checking on the separators 
     288     * This could lead to all kinds of problems. 
     289     *  
     290     * @return bool - true if we think they're acceptable. 
     291     */ 
     292    function acceptable_separators() { 
     293        $acceptable = true; 
     294        if ( $this->decimal_separator == $this->thousand_separator ) { 
     295            // wc_error(  
     296            $acceptable = false; 
     297            bw_trace2( $this->decimal_separator, "Decimal and thousand separators should not be the same", false );  
     298        } 
     299        if ( $this->decimal_separator == '|' ) { 
     300            $acceptable = false; 
     301            bw_trace2( $this->decimal_separator, "Non-acceptable value for decimal separator", false ); 
     302        } 
     303        if ( $this->thousand_separator == '|' ) { 
     304            $acceptable = false; 
     305            bw_trace2( $this->thousand_separator, "Non-acceptable value for thousand separator", false ); 
     306        } 
     307        return $acceptable; 
     308    } 
     309 
     310    /** 
     311     * Returns the rates table 
     312     * 
     313     * If it's not an array then we treat it as an unconverted options string. 
     314     * @TODO What if it's not set? 
     315     *  
     316     * @return array internal representation of the rates table 
     317     */ 
     318    function get_rates() { 
     319        $rates = $this->instance_settings['rates_table']; 
     320        //bw_trace2( $rates, "rates", false ); 
     321        if ( !$rates || !is_array( $rates) ) { 
     322            $this->delimiters = $this->dot_rate_delimiters; 
     323            $rates = $this->get_rates_table( $rates ); 
     324        } 
     325        return $rates; 
     326    } 
     327 
     328    /** 
     329     * Validates the rates field converting it to a rates array 
     330     * 
     331     * @param string $key 
     332     * @param string $value 
     333     * @return  
     334     */ 
     335    function validate_rates_field( $key, $value ) { 
     336        //bw_trace2(); 
     337        $this->delimiters = $this->allowed_delimiters; 
     338        $value = $this->get_rates_table( $value );  
     339        return $value; 
     340    } 
     341 
     342    /** 
     343     * Validate the fee to be a valid currency value 
     344     * 
     345     * Allow for local currency separators 
     346     * 
     347     */  
     348    function validate_fee_field( $key, $value ) { 
     349        $value = $this->get_value_as_decimal( $value ); 
     350        //bw_trace2(); 
     351        return $value; 
     352    } 
     353 
     354    /** 
     355     * Convert a rates table array to a rates display string 
     356     *  
     357     * Rates are stored internally as separate fields. 
     358     * On the front end it's a simple textarea field. 
     359     * 
     360     */ 
     361    function convert_rates_to_display() { 
     362        //bw_trace2( $this, "this", false ); 
     363        if ( !isset( $this->instance_settings['rates'] ) ) { 
     364            $this->instance_settings['rates'] = null; 
     365            $this->delimiters = $this->dot_rate_delimiters; 
     366        } 
     367        $this->instance_settings['rates_table'] = $this->instance_settings['rates']; 
     368        $rates_display = $this->rates_array_to_display( $this->instance_settings['rates'] ); 
     369        $this->instance_settings['rates'] = $rates_display; 
     370    } 
     371 
     372    /** 
     373     * Converts rates table to rates display 
     374     * 
     375     * @param array $rates 
     376     */ 
     377    function rates_array_to_display( $rates ) { 
     378        //bw_trace2(); 
     379        $rates = $this->get_rates_table( $rates ); 
     380        $rates_display = array(); 
     381        foreach ( $rates as $key => $rate ) { 
     382            $rates_display[] = $this->convert_rate_array_to_rate_display( $rate ); 
     383        } 
     384        $rates_display = implode( "\n", $rates_display );  
     385        $rates_display = stripslashes( $rates_display ); 
     386        return $rates_display; 
     387    } 
     388 
     389    /** 
     390     * Converts a rate array to an option string 
     391     *  
     392     *  
     393     *  
     394     * @param array $rate  
     395     * @return string $rate_display 
     396     */ 
     397     
     398    function convert_rate_array_to_rate_display( $rate ) { 
     399        $rate_display = array(); 
     400        $rate_display[] = $this->local_number( array_shift( $rate ) ); 
     401        $rate_display[] = $this->price( array_shift( $rate ) ); 
     402        $rate_display[] = stripslashes( implode( " ", $rate ) ); 
     403        $rate_display = implode( " | ", $rate_display ); 
     404        return( $rate_display ); 
     405    } 
     406 
     407    /** 
     408     * Display a localized number 
     409     *  
     410     * Used to Format the Max weight where the number of decimals is not limited. 
     411     * 
     412     * https://en.wikipedia.org/wiki/Decimal_mark 
     413     *  
     414     * @param string $value 
     415     * @return string localized decimal 
     416     */ 
     417    function local_number( $value ) { 
     418        if ( is_numeric( $value ) ) {  
     419            //$local_number = number_format( $value, 10 , $this->decimal_separator, $this->thousand_separator ); 
     420            //$local_number = rtrim( $local_number, "0" ); 
     421            //$local_number = rtrim( $local_number, "." ); 
     422            $local_number = wc_format_localized_decimal( $value ); 
     423        } else { 
     424            $local_number = $value; 
     425        } 
     426        //bw_trace2( $local_number, "local_number" ); 
     427        return( $local_number ); 
     428    }  
     429     
     430    /** 
     431     * Returns a localized price 
     432     *  
     433     * Note: Does not support negative values. 
     434     *  
     435     * @param string $value 
     436     * @return string localized version 
     437     */ 
     438    function price( $value ) { 
     439        if ( is_numeric( $value ) ) {  
     440            $price = number_format( $value, $this->decimals, $this->decimal_separator, $this->thousand_separator ); 
     441        } else { 
     442            $price = $value; 
     443        } 
     444        return $price; 
     445    } 
     446     
     447    /** 
     448     * Retrieves the original options string 
     449     *  
     450     * We can't use `$this->get_option("options")` since the "options" field is no longer part of the form. 
     451     * So we have to check for the existence of the field and return that if set. 
     452     *  
     453     * @return string|null value of 'options', if set 
     454     */ 
     455    function get_options() { 
     456        if ( isset( $this->instance_settings['options'] ) ) { 
     457            $options = $this->instance_settings['options']; 
     458        } else { 
     459            $options = null; 
     460        } 
     461        return $options; 
     462    } 
    175463 
    176464    /** 
    177465     * Retrieves all rates available 
    178466     * 
    179      * Now supports separators of '/' forward slash and ',' comma as well as vertical bar 
    180      * Also trims off blanks. 
    181      * 
    182      * @return array $rates - 
    183      */ 
    184     function get_rates() { 
    185         bw_trace2(); 
     467     * - If rates have not yet been converted then we load the values from "options" 
     468     * - Supports user defined currency separators  
     469     * - Supports field separators of forward slash, vertical bar and comma; if not used as a currency separator 
     470     * - Also trims off blanks. 
     471     * 
     472     * @param string $value 
     473     * @return array $rates_table 
     474     */ 
     475    function get_rates_table( $value=null ) { 
     476        if ( $value ) { 
     477            $rates = $value; 
     478        } else { 
     479            $rates = $this->get_options(); 
     480            //bw_backtrace(); 
     481            //bw_trace2( $this, "thus", false ); 
     482        } 
     483        //bw_trace2( $rates, "rates" );  
     484        if ( !is_array( $rates ) ) {             
     485            $rates_table = $this->convert_rates_display_to_rates_table( $rates ); 
     486        } else { 
     487            $rates_table = $rates; 
     488        } 
     489        return $rates_table; 
     490    } 
     491 
     492    /** 
     493     * Convert rates display to rates table 
     494     *  
     495     * @param string $rates_display 
     496     * @return array $rates - table 
     497     */ 
     498    function convert_rates_display_to_rates_table( $rates_display ) { 
    186499        $rates = array(); 
    187         $options = $this->get_option( "options" ); 
    188         bw_trace2( $options, "options", false ); 
    189         $options = trim( $options ); 
    190         if ( $options ) { 
    191             $options = (array) explode( "\n", $options ); 
    192             bw_trace2( $options, "options array", false ); 
    193             if ( sizeof( $options ) > 0) { 
    194                 foreach ( $options as $option => $value ) { 
    195                     $value = trim( $value ); 
    196                     $value = str_replace( array( "/", "," ), "|", $value ); 
    197                     $rate = explode( "|", $value ); 
    198                     foreach ( $rate as $key => $val ) { 
    199                         $rate[$key] = trim( $val ); 
    200                     } 
    201                     if ( !isset( $rate[2] ) ) { 
    202                         $rate[2] = null; 
    203                     } 
     500        //bw_trace2( $rates_display, "rates display", false ); 
     501        $rates_display = trim( $rates_display ); 
     502        if ( $rates_display ) { 
     503            $rates_display = (array) explode( "\n", $rates_display ); 
     504            //bw_trace2( $rates_display, "rates display array", false ); 
     505            if ( sizeof( $rates_display ) > 0) { 
     506                foreach ( $rates_display as $key => $value ) { 
     507                    $rate = $this->get_rate( $value ); 
    204508                    $this->set_shippingrate_title( $rate ); 
    205509                    $rates[] = $rate; 
    206510                } 
    207511            } 
    208         }      
    209         return( $rates ); 
     512        } 
     513        return $rates; 
    210514    } 
    211515     
     
    218522     */ 
    219523    function set_shippingrate_title( $rate ) { 
    220         bw_trace2(); 
    221         bw_backtrace(); 
    222524        //bw_trace2(); 
    223525        if ( isset( $rate[2] ) && $rate[2] != "" ) { 
     
    226528            $title = $this->title; 
    227529        } 
     530        $title = stripslashes( $title ); 
    228531        $this->shippingrate_title = $title; 
    229         return( $title ); 
     532        return $title ; 
    230533    }  
    231534  
     
    237540     */ 
    238541    function sort_ascending( $rates_array ) { 
    239         bw_trace2(); 
     542        //bw_trace2(); 
    240543        $weights = array(); 
    241544        $rates = array(); 
     
    269572     * 999|0.00| Free above 50, up to 999 
    270573     * 1000| X | Maximum weight supported is 999 
    271   * ` 
     574    * ` 
    272575     *  
    273576     * If the weight is above this highest value then the most expensive rate is chosen. 
     
    286589        $found = false; 
    287590        if ( sizeof( $rates_array ) > 0) { 
    288           $rates = $this->sort_ascending( $rates_array ); 
     591            $rates = $this->sort_ascending( $rates_array ); 
    289592            //bw_trace2( $rates, "rates" ); 
    290593            foreach ( $rates as $key => $value) { 
     
    325628        return( $html ); 
    326629    } 
     630     
     631    /** 
     632     * Generate OIK Weight Zone Shipping Textarea HTML. 
     633     * 
     634     * This is a copy of WC_Settings_API::generate_textarea_html with 
     635     * overrides for the rows and cols values  
     636     * and defaulting the width to 100% 
     637     * 
     638     * @param  mixed $key 
     639     * @param  mixed $data 
     640     * @return string 
     641     */ 
     642    public function generate_textarea_html( $key, $data ) { 
     643        $field_key = $this->get_field_key( $key ); 
     644        $defaults  = array( 
     645            'title'             => '', 
     646            'disabled'          => false, 
     647            'class'             => '', 
     648            'css'               => '', 
     649            'placeholder'       => '', 
     650            'type'              => 'text', 
     651            'desc_tip'          => false, 
     652            'description'       => '', 
     653            'custom_attributes' => array(), 
     654            'css' => "width: 100%;", 
     655        ); 
     656 
     657        $data = wp_parse_args( $data, $defaults ); 
     658 
     659        ob_start(); 
     660        ?> 
     661        <tr valign="top"> 
     662            <th scope="row" class="titledesc"> 
     663                <?php echo $this->get_tooltip_html( $data ); ?> 
     664                <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> 
     665            </th> 
     666            <td class="forminp"> 
     667                <fieldset> 
     668                    <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> 
     669                    <textarea rows="10" cols="30" class="input-text wide-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>><?php echo esc_textarea( $this->get_option( $key ) ); ?></textarea> 
     670                    <?php echo $this->get_description_html( $data ); ?> 
     671                </fieldset> 
     672            </td> 
     673        </tr> 
     674        <?php 
     675 
     676        return ob_get_clean(); 
     677    } 
    327678     
    328679} // end OIK_Weight_Zone_Shipping 
  • oik-weight-zone-shipping/trunk/oik-weight-zone-shipping.php

    r1630308 r1659385  
    44 * Plugin URI: https://www.oik-plugins.com/oik-plugins/oik-weight-zone-shipping 
    55 * Description: Weight zone shipping for WooCommerce 
    6  * Version: 0.0.3 
     6 * Version: 0.1.0 
    77 * Author: bobbingwide 
    88 * Author URI: https://www.oik-plugins.com/author/bobbingwide 
     
    6666 * Implement "woocommerce_init" 
    6767 * 
    68  * Only enabl the logic if the minimum required version of WooCommerce is active   
     68 * Only enable the logic if the minimum required version of WooCommerce is active   
    6969 */ 
    7070function oik_weight_zone_shipping_woocommerce_init() { 
     
    7272        add_filter( 'woocommerce_shipping_methods', 'oik_weight_zone_woocommerce_shipping_methods' ); 
    7373        add_action( 'woocommerce_shipping_init', 'oik_weight_zone_woocommerce_shipping_init' ); 
     74        add_filter( 'woocommerce_shipping_rate_label', 'oik_weight_zone_shipping_shipping_rate_label', 9 ); 
    7475    } 
    7576} 
     77 
    7678 
    7779/** 
     
    9092} 
    9193 
     94/** 
     95 * Disables the sanitize_text_field filter to allow HTML in the label 
     96 *  
     97 *  
     98 * Out of the box, WooCommerce doesn't allow HTML in the label.  
     99 * We intercept this filter simply to disable the filter that WooCommerce added. 
     100 * The user is responsible for ensuring tags are paired. 
     101 * There's no real need to check if the $label contains any HTML. 
     102 * Removing the filter multiple times is not a problem. 
     103 *  
     104 * @param string $label which may contain HTML 
     105 * @return string the same 
     106 */ 
     107function oik_weight_zone_shipping_shipping_rate_label( $label ) {  
     108    remove_filter( "woocommerce_shipping_rate_label", "sanitize_text_field" ); 
     109    return $label; 
     110}            
     111 
    92112if ( !function_exists( "bw_trace2" ) ) { 
    93113  function bw_trace2( $p=null ) { return $p; } 
  • oik-weight-zone-shipping/trunk/readme.txt

    r1630308 r1659385  
    44Tags: shipping, weight, zone, woocommerce 
    55Requires at least: 4.5.2 
    6 Tested up to: 4.7.3 
    7 Stable tag: 0.0.3 
     6Tested up to: 4.7.5 
     7Stable tag: 0.1.0 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    4646= What is the separator for the shipping rate table? =  
    4747 
    48 You can use vertical bars, forward slashes or commas. 
    49 Blanks around values will be ignored. 
     48Vertical bars. Blanks around values will be ignored. 
    5049 
    5150` 
    52 0| 9.99| Zero weight 
    53 1 / 1.24 /  
    54 2 , 3.45 , 
     510 | 9.99| Zero weight 
     521 | 1.24 |  
     532 | 3.45 | 
    55543 | 4.56  
    5655` 
    5756 
    58 Enter one rate per line. 
     57* Use of slash characters are no longer supported as these are now allowed in the Method Title override. 
     58* Whether or not you can use a comma depends on your Currency options.  
     59* If your Thousand or Decimal separator is a comma then it can't be used as a field delimiter. 
     60* Enter one rate per line. 
    5961 
    6062 
     
    6466 
    6567` 
    66 0| 9.99| Zero weight 
    67 1 / 1.24 /   
    68 2 , 3.45 ,  
    69 3 | 4.56 , Another method title override 
     680 | 9.99| Zero weight 
     691 | 1.24 | 
     702 | 3.45 | 
     713 | 4.56 | Another method title override 
    707210 | 0 | Free shipping between 3 and 10 kgs 
    7173999 | ZZZ | Maximum cart weight is 10 kgs 
     
    9496 
    9597== Screenshots == 
    96 1. Add Shipping Method for Weight zone shipping 
    97 2. Weight zone shipping - initial display 
    98 3. Weight zone shipping rates 
    99 4. Weight zone settings - modal 
     981. Add Shipping Method for Weight Zone 
     992. Weight Zone Settings - initial display 
     1003. Weight Zone Settings - shipping rates defined 
    1001015. Cart totals 
    101 6. Checkout shipping rate 
    102 7. WooCommerce > System Status > Tools > Shipping debug mode 
     1026. Checkout shipping rates 
    103103 
    104104== Upgrade Notice == 
     105= 0.1.0 = 
     106Now supports local currency format and HTML in the shipping method title override. 
     107 
    105108= 0.0.3 =  
    106109Tested with WooCommerce 3.0, WordPress 4.7.3 and PHP 7.1  
     
    118121 
    119122== Changelog == 
     123= 0.1.0 = 
     124* Changed: Add logic to format weight; using WooCommerce functions 
     125* Changed: Added Swedish language. Props @jyourstone 
     126* Changed: Improve styling of the Shipping rates textarea field [github bobbingwide oik-weight-zone-shipping issues 19] 
     127* Changed: Reconcile with oik-weight-zone-shipping-pro [github bobbingwide oik-weight-zone-shipping issues 3] 
     128* Changed: Support HTML in the method title override [github bobbingwide oik-weight-zone-shipping issues 18] 
     129* Changed: Supports local currency separators in Cost and Fee fields [github bobbingwide oik-weight-zone-shipping issues 11] 
     130* Tested: with WooCommerce 3.0, WordPress 4.7.4 and PHP 7.1 [github bobbingwide oik-weight-zone-shipping issues 14] 
     131 
    120132= 0.0.3 = 
    121133* Tested: With WooCommerce 3.0, [Issue 14](https://github.com/bobbingwide/oik-weight-zone-shipping/issues/14) 
Note: See TracChangeset for help on using the changeset viewer.