WordPress.org

Plugin Directory

Changeset 1609491


Ignore:
Timestamp:
03/07/17 08:39:48 (5 months ago)
Author:
sormano
Message:

Versioning WAFS 1.1.0

Location:
woocommerce-advanced-free-shipping
Files:
88 added
6 deleted
32 edited
1 copied

Legend:

Unmodified
Added
Removed
  • woocommerce-advanced-free-shipping/tags/1.1.0/assets/css/woocommerce-advanced-free-shipping.min.css

    r1490367 r1609491  
    1 .wpc-conditions .wpc-condition-group{margin-bottom:30px;background-color:#f5f5f5;padding:15px 20px 20px;border:1px solid #ddd;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04);min-height:30px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap{margin:10px 0 5px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-condition{width:30%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-operator{width:12%;min-width:140px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-value{width:30%;height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description{float:right}.wpc-conditions .wpc-condition-group .wpc-condition-wrap input{vertical-align:top}.wpc-conditions .or-text{display:none !important}.wpc-conditions .wpc-condition-group ~ .or-text,.wpc-conditions .wpc-condition-group ~ .or-text ~ .wpc-condition-group .or-text{display:block !important}.wpc-conditions .wpc-condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wpc-conditions .wpc-condition-wrap:hover .wpc-condition-delete{display:inline-block;opacity:1}.wpc-conditions .wpc-condition-wrap.loading{height:30px}.wpc-conditions .wpc-condition-wrap.loading .loading-icon{width:100%;clear:both;display:block;text-align:center;line-height:110%;margin:0 1px}.wpc-condition-wrap .wpc-value.select2-container{display:inline-block !important;margin:1px}.wpc-condition-wrap .wpc-value.select2-container.select2-container-active .select2-choice{border:1px solid #666}.wpc-condition-wrap .wpc-value.select2-container.select2-drop-above .select2-choice{border-radius:0 0 4px 4px;border:1px solid #666;border-top-color:transparent}.wpc-condition-wrap .wpc-value.select2-container .select2-choice{border-color:#ddd;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;height:26px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);box-shadow:inset 0 1px 2px rgba(0,0,0,0.07)}.wpc-condition-wrap .wpc-value.select2-dropdown-open .select2-choice{border-bottom-color:transparent;-webkit-box-shadow:0 1px 0 #fff inset;box-shadow:0 1px 0 #fff inset;border-bottom-left-radius:0;border-bottom-right-radius:0;border:1px solid #666;outline:0}.wpc-conditions-post-table .sort{padding:0 4px;cursor:move;text-align:center;vertical-align:middle}.wpc-conditions-post-table .sort:before{content:"\e032";font-family:WooCommerce;text-align:center;line-height:1;color:#999;display:block;width:100%;float:left;height:100%}.wpc-conditions-post-table .sort:before,.wpc-conditions-post-table .row-actions{visibility:hidden !important}.wpc-conditions-post-table tr:hover .sort:before,.wpc-conditions-post-table tr:hover>td>.row-actions{visibility:visible !important}.wpc-conditions-post-table .add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}.wpc-currency{padding:3px 10px;font-size:14px;font-weight:400;line-height:19px;height:27px;box-sizing:border-box;color:#555;text-align:center;background-color:#EEE;border:1px solid #DDD;border-right:none;border-radius:4px 0px 0px 4px;margin:1px 0px 1px 1px;display:inline-block}.wpc-currency+input{margin-left:-4px;line-height:19px;width:161px !important}.post-type-wafs .misc-pub-visibility#visibility{display:none}.wafs-option label{display:inline-block;width:150px}.wafs_conditions_meta_box>p:first-child+div>.or_match{display:none}.condition-group{margin-bottom:30px;background-color:#f5f5f5;padding:15px 20px 20px;border:1px solid #ddd;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04)}.wafs-condition-wrap{margin:10px 0px 5px}.wafs-condition-wrap .wafs-condition{width:30%}.wafs-condition-wrap .wafs-operator{width:12%;min-width:140px}.wafs-condition-wrap .wafs-value{width:30%}.wafs-condition-wrap input{vertical-align:top}#wafs_conditions p+p{display:none}.wafs_desc{display:none;position:absolute;background:rgba(0,0,0,0.8);min-width:25px;max-width:200px;border-radius:6px;padding:5px 10px;color:white;margin-top:10px;right:40px;text-align:center}.wafs_desc:after{border-top:0px solid transparent;border-right:10px solid transparent;border-left:10px solid transparent;border-bottom:10px solid rgba(0,0,0,0.8);content:' ';position:absolute;top:-10px;right:10px;z-index:999}.wafs_tip:hover ~ .wafs_desc{display:block !important}.wafs-description{width:40px;float:right;line-height:20px}.wafs-condition-wrap ~ .loading-icon{display:block}.loading-icon{width:30%;clear:both;display:inline-block;text-align:center;line-height:110%;margin:0 1px}.condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wafs-condition-wrap:hover .condition-delete{display:inline-block;opacity:1}.add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}#advanced_free_shipping_shipping_methods tr .row-actions{visibility:hidden}#advanced_free_shipping_shipping_methods tr:hover>td>.row-actions{visibility:visible !important} 
     1.wpc-conditions .wpc-condition-group{background-color:#f5f5f5;padding:15px;border:1px solid #e5e5e5;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04);min-height:30px;margin:0 -13px 1.5em}.wpc-conditions .wpc-condition-group:hover .wpc-condition-group-actions{opacity:1}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions{opacity:0;margin:-10px -10px 0 0;font-size:80%}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a{text-decoration:none}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete{color:#a00}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete:hover{color:#f00}.wpc-conditions .wpc-condition-group .wpc-condition-wrap{margin:10px 0 5px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-condition{width:35%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-operator{width:22.5%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-value{width:calc( 42.5% - 75px );height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description{float:right}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip{height:28px;line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip:after{line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap input{vertical-align:top}.wpc-conditions .clearfix:after{content:" ";display:block;height:0;clear:both}.wpc-conditions .wpc-add.button:before{font-family:'dashicons';content:"\f502";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;margin-right:5px;color:#667}.wpc-conditions .wpc-condition-delete.button{font-weight:600;width:30px;text-align:center;padding:0}.wpc-conditions .wpc-condition-delete.button:before{font-family:'dashicons';content:"\f460";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;color:#667}.wpc-conditions>p+.wpc-condition-group-wrap p.or-text{display:none}.wpc-conditions .or-text{margin:1.5em 0}.wpc-conditions .match-text{margin:0 0 1em}.wpc-conditions .wpc-condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wpc-conditions .wpc-condition-wrap:hover .wpc-condition-delete{display:inline-block;opacity:1}.wpc-conditions .wpc-condition-wrap.loading{height:30px}.wpc-conditions .wpc-condition-wrap.loading .loading-icon{width:100%;clear:both;display:block;text-align:center;line-height:110%;margin:0 1px}.wpc-condition-wrap .wpc-value.select2-container{display:inline-block !important;margin:1px}.wpc-condition-wrap .wpc-value.select2-container.select2-container-active .select2-choice{border:1px solid #666}.wpc-condition-wrap .wpc-value.select2-container.select2-drop-above .select2-choice{border-radius:0 0 4px 4px;border:1px solid #666;border-top-color:transparent}.wpc-condition-wrap .wpc-value.select2-container .select2-choice{border-color:#ddd;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;height:26px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);box-shadow:inset 0 1px 2px rgba(0,0,0,0.07)}.wpc-condition-wrap .wpc-value.select2-dropdown-open .select2-choice{border-bottom-color:transparent;-webkit-box-shadow:0 1px 0 #fff inset;box-shadow:0 1px 0 #fff inset;border-bottom-left-radius:0;border-bottom-right-radius:0;border:1px solid #666;outline:0}.wpc-condition-wrap .select2-container .select2-selection--single{height:28px !important}.wpc-condition-wrap .select2-container .select2-selection--single #select2--container,.wpc-condition-wrap .select2-container .select2-selection--single .select2-selection__arrow{line-height:26px}.wpc-condition-wrap .select2-container .select2-selection--single .select2-selection__arrow{height:28px}.wpc-conditions-post-table .sort{padding:0 4px;cursor:move;text-align:center;vertical-align:middle}.wpc-conditions-post-table .sort:before{content:"\e032";font-family:WooCommerce;text-align:center;line-height:1;color:#999;display:block;width:100%;float:left;height:100%}.wpc-conditions-post-table .sort:before,.wpc-conditions-post-table .row-actions{visibility:hidden !important}.wpc-conditions-post-table tr:hover .sort:before,.wpc-conditions-post-table tr:hover>td>.row-actions{visibility:visible !important}.wpc-conditions-post-table .add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}@media screen and (max-width: 782px){.wpc-conditions-post-table th{padding:8px}.wpc-conditions-post-table td{padding:8px 10px}.wpc-conditions-post-table tfoot .button{margin-bottom:0}}.wpc-currency{padding:3px 10px;font-size:14px;font-weight:400;line-height:19px;height:27px;box-sizing:border-box;color:#555;text-align:center;background-color:#EEE;border:1px solid #DDD;border-right:none;border-radius:4px 0px 0px 4px;margin:1px 0px 1px 1px;display:inline-block}.wpc-currency+input{margin-left:-4px;line-height:19px;width:161px !important}@media screen and (max-width: 782px){.wpc-currency{font-size:16px;padding:6px 10px;height:33px}}.post-type-wafs .misc-pub-visibility#visibility{display:none}.wafs-option label{display:inline-block;width:150px}.wafs_conditions_meta_box>p:first-child+div>.or_match{display:none}.wafs_desc{display:none;position:absolute;background:rgba(0,0,0,0.8);min-width:25px;max-width:200px;border-radius:6px;padding:5px 10px;color:white;margin-top:10px;right:40px;text-align:center}.wafs_desc:after{border-top:0px solid transparent;border-right:10px solid transparent;border-left:10px solid transparent;border-bottom:10px solid rgba(0,0,0,0.8);content:' ';position:absolute;top:-10px;right:10px;z-index:999}.wafs_tip:hover ~ .wafs_desc{display:block !important}.wafs-description{width:40px;float:right;line-height:20px}.condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wafs-condition-wrap:hover .condition-delete{display:inline-block;opacity:1}#advanced_free_shipping_shipping_methods tr .row-actions{visibility:hidden}#advanced_free_shipping_shipping_methods tr:hover>td>.row-actions{visibility:visible !important} 
  • woocommerce-advanced-free-shipping/tags/1.1.0/assets/css/woocommerce-advanced-free-shipping.scss

    r1483190 r1609491  
    1 @import 'parts/wp-conditions'; 
     1@import '../../libraries/wp-conditions/assets/css/wp-conditions'; 
    22 
    33/* Hide visibility from admin */ 
     
    1414    display: none; 
    1515} 
    16 /* 
    17  * Condition group 
    18  */ 
    19 .condition-group { 
    20     margin-bottom: 30px; 
    21     background-color: #f5f5f5; 
    22     padding: 15px 20px 20px; 
    23     border: 1px solid #ddd; 
    24     -webkit-box-shadow: 0 1px 1px rgba( 0, 0, 0, .04); 
    25     box-shadow: 0 1px 1px rgba( 0, 0, 0, .04); 
    26 } 
    27 .wafs-condition-wrap { 
    28     margin: 10px 0px 5px; 
    29 } 
    30 .wafs-condition-wrap .wafs-condition { 
    31     width: 30%; 
    32 } 
    33 .wafs-condition-wrap .wafs-operator { 
    34     width: 12%; 
    35     min-width: 140px; 
    36 } 
    37 .wafs-condition-wrap .wafs-value { 
    38     width: 30%; 
    39 } 
    40 .wafs-condition-wrap input { 
    41     vertical-align: top; 
    42 } 
    4316 
    44 #wafs_conditions p + p { 
    45     display: none; 
    46 } 
    4717/* Description */ 
    4818.wafs_desc { 
     
    7949} 
    8050 
    81 /* 
    82  * Loading icon 
    83  */ 
    84  
    85 /* Load icon condition row */ 
    86 .wafs-condition-wrap ~ .loading-icon { 
    87     display: block; 
    88 } 
    89 .loading-icon { 
    90     width: 30%; 
    91     clear: both; 
    92     display: inline-block; 
    93     text-align: center; 
    94     line-height: 110%; 
    95     margin: 0 1px; 
    96 } 
    97  
    9851.condition-delete { 
    9952    display: none; 
     
    10659} 
    10760 
    108  
    109 /* WooCommerce Add icon */ 
    110 .add.button:before { 
    111     font-family: WooCommerce; 
    112     speak: none; 
    113     font-weight: 400; 
    114     font-variant: normal; 
    115     text-transform: none; 
    116     line-height: 1; 
    117     -webkit-font-smoothing: antialiased; 
    118     margin-right: 7px; 
    119     content: "\e007"; 
    120 } 
    12161/* Overview row actions */ 
    12262#advanced_free_shipping_shipping_methods tr .row-actions { 
  • woocommerce-advanced-free-shipping/tags/1.1.0/codeoversight.yml

    r1483190 r1609491  
    11php: 
    22    align_array_elements: space 
    3     align_doc_tags: double_space 
     3    align_doc_tags: space 
    44    align_variables: space 
    55    closing_newline: add 
     
    2727    use_quotes: single_quotes 
    2828    variable_array_index_whitespace: whitespace 
    29     whitespace_after_control_structure: whitespace 
    3029    whitespace_after_doc_asterisk: single_space 
    3130    whitespace_after_else: space 
     
    3332    whitespace_after_function: double_newline 
    3433    whitespace_before_control_structure_brace: space 
     34    whitespace_before_control_structure_parentheses: whitespace 
    3535    whitespace_before_doc_asterisk: space 
    3636    whitespace_before_else: space 
     
    3838    whitespace_before_function_close: newline 
    3939    whitespace_before_function_parentheses: no_space 
     40 
     41blacklist: 
     42  directories: 
     43    - libraries 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/admin/class-wafs-admin.php

    r1483190 r1609491  
    1919     * @since 1.0.8 
    2020     */ 
    21     public function __construct() { 
    22  
    23         // Initialize plugin parts 
    24         add_action( 'admin_init', array( $this, 'init' ) ); 
    25  
    26     } 
     21    public function __construct() {} 
    2722 
    2823 
     
    4540        global $pagenow; 
    4641        if ( 'plugins.php' == $pagenow ) : 
    47             // Plugins page 
    4842            add_filter( 'plugin_action_links_' . plugin_basename( WAFS()->file ), array( $this, 'add_plugin_action_links' ), 10, 2 ); 
    4943        endif; 
     
    6559        wp_register_style( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/css/woocommerce-advanced-free-shipping.min.css', WAFS()->file ), array(), WAFS()->version ); 
    6660        wp_register_script( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/js/woocommerce-advanced-free-shipping' . $suffix . '.js', WAFS()->file ), array( 'jquery' ), WAFS()->version, true ); 
    67         wp_localize_script( 'woocommerce-advanced-free-shipping', 'wpc', array( 
    68             'nonce'         => wp_create_nonce( 'wpc-ajax-nonce' ), 
    69             'action_prefix' => 'wafs_', 
    70             'asset_url'     => plugins_url( 'assets/', WAFS()->file ), 
     61        wp_localize_script( 'woocommerce-advanced-free-shipping', 'wafs', array( 
     62            'nonce' => wp_create_nonce( 'wpc-ajax-nonce' ), 
    7163        ) ); 
    7264 
     
    7769        ) : 
    7870 
     71            wp_localize_script( 'wp-conditions', 'wpc2', array( 
     72                'action_prefix' => 'wafs_', 
     73            ) ); 
     74 
    7975            wp_enqueue_style( 'woocommerce-advanced-free-shipping' ); 
    8076            wp_enqueue_script( 'woocommerce-advanced-free-shipping' ); 
     77            wp_enqueue_script( 'wp-conditions' ); 
     78 
    8179            wp_dequeue_script( 'autosave' ); 
    8280 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/admin/class-wafs-condition.php

    r1490367 r1609491  
    5959     * @since 1.0.0 
    6060     */ 
    61     public function __construct( $id = null, $group = 0, $condition = null, $operator = null, $value = null ) { 
     61    public function __construct( $id = null, $group = 0, $condition = 'subtotal', $operator = null, $value = null ) { 
    6262 
    6363        $this->id        = $id; 
     
    145145     */ 
    146146    public function get_operators() { 
    147  
    148         $operators = array( 
    149             '==' => __( 'Equal to', 'woocommerce-advanced-free-shipping' ), 
    150             '!=' => __( 'Not equal to', 'woocommerce-advanced-free-shipping' ), 
    151             '>=' => __( 'Greater or equal to', 'woocommerce-advanced-free-shipping' ), 
    152             '<=' => __( 'Less or equal to ', 'woocommerce-advanced-free-shipping' ), 
    153         ); 
    154         $operators = apply_filters( 'wafs_operators', $operators ); 
    155  
    156         return $operators; 
    157  
     147        $wpc_condition = wpc_get_condition( $this->condition ); 
     148        return apply_filters( 'woocommerce_Advanced_Shipping_Validation_operators', $wpc_condition->get_available_operators() ); 
    158149    } 
    159150 
     
    172163 
    173164        // Defaults 
    174         $values = array( 
     165        $default_field_args = array( 
    175166            'name'        => 'conditions[' . absint( $this->group ) . '][' . absint( $this->id ) . '][value]', 
    176167            'placeholder' => '', 
    177168            'type'        => 'text', 
    178             'class'       => array( 'wpc-value' ) 
     169            'class'       => array( 'wpc-value' ), 
    179170        ); 
    180171 
    181  
    182  
    183         switch ( $this->condition ) : 
    184  
    185             default: 
    186             case 'subtotal' : 
    187             case 'subtotal_ex_tax' : 
    188             case 'tax' : 
    189             case 'quantity' : 
    190             case 'coupon' : 
    191             case 'weight' : 
    192                 $values['type'] = 'text'; 
    193             break; 
    194  
    195             case 'contains_product' : 
    196  
    197                 $product = wc_get_product( $this->value ); 
    198                 if ( $product ) { 
    199                     $values['custom_attributes']['data-selected'] = $product->get_formatted_name(); 
    200                 } 
    201  
    202                 $values['type']        = 'text'; 
    203                 $values['placeholder'] =  __( 'Search for a product', 'woocommerce-advanced-messages' ); 
    204                 $values['class'][]     = 'wc-product-search'; 
    205  
    206             break; 
    207  
    208             case 'contains_shipping_class' : 
    209  
    210                 $values['type']        = 'select'; 
    211                 $values['options'][''] = __( 'No shipping class', 'woocommerce' ); 
    212  
    213                 // Get all shipping classes 
    214                 foreach ( get_terms( 'product_shipping_class', array( 'hide_empty' => false ) ) as $shipping_class ) : 
    215                     $values['options'][ $shipping_class->slug ] = $shipping_class->name; 
    216                 endforeach; 
    217  
    218             break; 
    219  
    220             /** 
    221              * User details 
    222              */ 
    223  
    224             case 'zipcode' : 
    225             case 'city' : 
    226                 $values['type'] = 'text'; 
    227             break; 
    228  
    229             case 'state' : 
    230  
    231                 $values['type']    = 'select'; 
    232                 $values['class'][] = 'wc-enhanced-select'; 
    233  
    234                 $country_states = array(); 
    235                 foreach ( WC()->countries->states as $country => $states ) : 
    236  
    237                     if ( empty( $states ) ) continue; // Don't show country if it has no states 
    238                     if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries 
    239  
    240                     foreach ( $states as $state_key => $state ) : 
    241                         $country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state; 
    242                     endforeach; 
    243  
    244                     $values['options'] = $country_states; 
    245  
    246                 endforeach; 
    247  
    248             break; 
    249  
    250             case 'country' : 
    251  
    252                 $values['field']   = 'select'; 
    253                 $values['class'][] = 'wc-enhanced-select'; 
    254  
    255                 $countries  =  WC()->countries->get_allowed_countries() + WC()->countries->get_shipping_countries(); 
    256                 $continents = array(); 
    257                 if ( method_exists( WC()->countries, 'get_continents' ) ) : 
    258                     foreach ( WC()->countries->get_continents() as $k => $v ) : 
    259                         $continents[ 'CO_' . $k ] = $v['name']; // Add prefix for country key compatibility 
    260                     endforeach; 
    261                 endif; 
    262  
    263                 if ( $continents ) { 
    264                     $values['options'][ __( 'Continents', 'woocommerce' ) ] = $continents; 
    265                 } 
    266                 $values['options'][ __( 'Countries', 'woocommerce' ) ] = $countries; 
    267  
    268                 break; 
    269  
    270             case 'role' : 
    271                 $values['type']    = 'select'; 
    272                 $roles             = array_keys( get_editable_roles() ); 
    273                 $values['options'] = array_combine( $roles, $roles ); 
    274             break; 
    275  
    276             /** 
    277              * Product 
    278              */ 
    279  
    280             case 'width' : 
    281             case 'height' : 
    282             case 'length' : 
    283             case 'stock' : 
    284                 $values['type'] = 'text'; 
    285             break; 
    286  
    287             case 'stock_status' : 
    288  
    289                 $values['type']    = 'select'; 
    290                 $values['options'] = array( 
    291                     'instock'    => __( 'In stock', 'woocommerce-advanced-free-shipping' ), 
    292                     'outofstock' => __( 'Out of stock', 'woocommerce-advanced-free-shipping' ), 
    293                 ); 
    294  
    295             break; 
    296  
    297             case 'category' : 
    298  
    299                 $values['type']    = 'select'; 
    300                 $values['class'][] = 'wc-enhanced-select'; 
    301  
    302                 $categories = get_terms( 'product_cat', array( 'hide_empty' => false ) ); 
    303                 foreach ( $categories as $category ) : 
    304                     $values['options'][ $category->slug ] = $category->name; 
    305                 endforeach; 
    306  
    307             break; 
    308  
    309  
    310         endswitch; 
    311  
    312         $values = apply_filters( 'wafs_values', $values, $this->condition ); 
    313  
    314  
    315         $values = apply_filters( 'woocommerce_advanced_free_shipping_values', $values, $this->condition ); 
    316  
    317         return $values; 
     172        $field_args = $default_field_args; 
     173        if ( $condition = wpc_get_condition( $this->condition ) ) { 
     174            $field_args = wp_parse_args( $condition->get_value_field_args(), $field_args ); 
     175        } 
     176 
     177        if ( $this->condition == 'contains_product' && $product = wc_get_product( $this->value ) ) { 
     178            $field_args['custom_attributes']['data-selected'] = $product->get_formatted_name(); // WC < 2.7 
     179            $field_args['options'][ $this->value ] = $product->get_formatted_name(); // WC >= 2.7 
     180        } 
     181 
     182        $field_args = apply_filters( 'wafs_values', $field_args, $this->condition ); 
     183        $field_args = apply_filters( 'woocommerce_advanced_free_shipping_values', $field_args, $this->condition ); 
     184 
     185        return $field_args; 
    318186 
    319187    } 
     
    328196     */ 
    329197    public function get_description() { 
    330  
    331         $descriptions = array( 
    332             'state'                   => __( 'States must be installed in WC.', 'woocommerce-advanced-free-shipping' ), 
    333             'weight'                  => __( 'Weight calculated on all the cart contents', 'woocommerce-advanced-free-shipping' ), 
    334             'length'                  => __( 'Compared to lengthiest product in cart', 'woocommerce-advanced-free-shipping' ), 
    335             'width'                   => __( 'Compared to widest product in cart', 'woocommerce-advanced-free-shipping' ), 
    336             'height'                  => __( 'Compared to highest product in cart', 'woocommerce-advanced-free-shipping' ), 
    337             'stock_status'            => __( 'All products in cart must match stock status', 'woocommerce-advanced-free-shipping' ), 
    338             'category'                => __( 'All products in cart must match category', 'woocommerce-advanced-free-shipping' ), 
    339             'contains_product'        => __( 'Cart must contain one of this product', 'woocommerce-advanced-free-shipping' ), 
    340             'contains_shipping_class' => __( 'Cart must contain at least one product with the selected shipping class', 'woocommerce-advanced-free-shipping' ), 
    341         ); 
    342  
    343         $descriptions = apply_filters( 'wafs_descriptions', $descriptions ); 
    344  
     198        $descriptions = apply_filters( 'wafs_descriptions', wpc_condition_descriptions() ); 
    345199        return isset( $descriptions[ $this->condition ] ) ? $descriptions[ $this->condition ] : ''; 
    346  
    347200    } 
    348201 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/admin/views/conditions-table.php

    r1483190 r1609491  
    2020    <td class="forminp" id="<?php echo $this->id; ?>_shipping_methods"> 
    2121 
    22         <table class='wp-list-table wpc-conditions-post-table widefat'> 
     22        <table class='wp-list-table wpc-conditions-post-table wpc-sortable-post-table widefat'> 
    2323            <thead> 
    2424                <tr> 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/admin/views/html-condition-row.php

    r1483190 r1609491  
    11<?php 
    22if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 
     3 
     4$condition = wpc_get_condition( $wp_condition->condition ); 
    35 
    46?><div class='wpc-condition-wrap'> 
    57 
    68    <!-- Condition --> 
    7     <span class='wpc-condition-wrap wpc-condition-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
     9    <span class='wpc-condition-field-wrap'><?php 
    810 
    911        $condition_field_args = array( 
     
    1416            'value'       => $wp_condition->condition, 
    1517            'custom_attr' => array( 
    16                 'data-group' => absint( $wp_condition->group ), 
    17                 'data-id'    => absint( $wp_condition->id ), 
     18                'data-id' => absint( $wp_condition->id ), 
    1819            ), 
    1920        ); 
     
    2425 
    2526    <!-- Operator --> 
    26     <span class='wpc-operator-wrap wpc-operator-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
     27    <span class='wpc-operator-field-wrap'><?php 
    2728 
    2829        $operator_field_args = array( 
     
    3940 
    4041    <!-- Value --> 
    41     <span class='wpc-value-wrap wpc-value-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
     42    <span class='wpc-value-field-wrap'><?php 
    4243        $value_field_args = wp_parse_args( array( 'value' => $wp_condition->value ), $wp_condition->get_value_field_args() ); 
    4344        wpc_html_field( $value_field_args ); 
     
    4546 
    4647 
    47     <!-- Add / Delete--> 
    48     <a class='button wpc-condition-add' data-group='<?php echo absint( $this->group ); ?>' href='javascript:void(0);'>+</a>&nbsp; 
    49     <a class='button wpc-condition-delete' href='javascript:void(0);'>-</a><?php 
     48    <!-- Delete--> 
     49    <a class='button wpc-condition-delete' href='javascript:void(0);'></a><?php 
    5050 
    5151 
    5252    // Description 
    5353    if ( $desc = $wp_condition->get_description() ) : 
    54         ?><span class='wpc-description <?php echo $wp_condition->condition; ?>-description'> 
    55             <img class='help_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' data-tip="<?php echo esc_html( $desc ); ?>" /> 
     54        ?><span class='wpc-description'> 
     55            <span class="woocommerce-help-tip" data-tip="<?php echo wp_kses_post( $desc ); ?>"></span> 
    5656        </span><?php 
    5757    else : 
    58         ?><span class='wpc-description wpc-no-description <?php echo $wp_condition->condition; ?>-description'><?php 
     58        ?><span class='wpc-description wpc-no-description'><?php 
    5959    endif; 
    6060 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/admin/views/meta-box-conditions.php

    r1483190 r1609491  
    88 
    99    <p> 
    10         <strong><?php _e( 'Match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong> 
     10        <strong><?php _e( 'Match one of the condition groups to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong> 
    1111    </p><?php 
    1212 
     
    1414 
    1515        foreach ( $condition_groups as $condition_group => $conditions ) : 
    16  
    17             ?><div class='wpc-condition-group wpc-condition-group-<?php echo absint( $condition_group ); ?>' data-group='<?php echo absint( $condition_group ); ?>'> 
    18  
    19                 <p class='or-text'><?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></p><?php 
    20  
    21                 foreach ( $conditions as $condition_id => $condition ) : 
    22                     $wp_condition = new WAFS_Condition( $condition_id, $condition_group, $condition['condition'], $condition['operator'], $condition['value'] ); 
    23                     $wp_condition->output_condition_row(); 
    24                 endforeach; 
    25  
    26             ?></div> 
    27  
    28             <p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php 
    29  
     16            include plugin_dir_path( __FILE__ ) . 'html-condition-group.php'; 
    3017        endforeach; 
    3118 
    3219    else : 
    3320 
    34         ?><div class='wpc-condition-group wpc-condition-group-0' data-group='0'><?php 
    35             $wp_condition = new WAFS_Condition(); 
    36             $wp_condition->output_condition_row(); 
    37         ?></div><?php 
     21        $condition_group = '0'; 
     22        include plugin_dir_path( __FILE__ ) . 'html-condition-group.php'; 
    3823 
    3924    endif; 
    4025 
    41     ?></div> 
     26?></div> 
    4227 
     28<div class='wpc-condition-group-template hidden' style='display: none'><?php 
     29    $condition_group = '9999'; 
     30    $conditions      = array(); 
     31    include plugin_dir_path( __FILE__ ) . 'html-condition-group.php'; 
     32?></div> 
    4333<a class='button wpc-condition-group-add' href='javascript:void(0);'><?php _e( 'Add \'Or\' group', 'woocommerce-advanced-free-shipping' ); ?></a> 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/admin/views/meta-box-settings.php

    r1483190 r1609491  
    3333    </p> 
    3434 
    35  
    3635</div> 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/class-wafs-ajax.php

    r1483190 r1609491  
    2020    public function __construct() { 
    2121 
    22         // Add elements 
    23         add_action( 'wp_ajax_wafs_add_condition', array( $this, 'add_condition' ) ); 
    24         add_action( 'wp_ajax_wafs_add_condition_group', array( $this, 'add_condition_group' ) ); 
    25  
    2622        // Update elements 
    2723        add_action( 'wp_ajax_wafs_update_condition_value', array( $this, 'update_condition_value' ) ); 
    28         add_action( 'wp_ajax_wafs_update_condition_description', array( $this, 'update_condition_description' ) ); 
    29  
    30     } 
    31  
    32  
    33     /** 
    34      * Add condition. 
    35      * 
    36      * Output the HTML of a new condition row. 
    37      * 
    38      * @since 1.0.0 
    39      */ 
    40     public function add_condition() { 
    41  
    42         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    43  
    44         $wp_condition = new WAFS_Condition( null, $_POST['group'] ); 
    45         $wp_condition->output_condition_row(); 
    46  
    47         die(); 
    48  
    49     } 
    50  
    51  
    52     /** 
    53      * Condition group. 
    54      * 
    55      * Output the HTML of a new condition group. 
    56      * 
    57      * @since 1.0.0 
    58      */ 
    59     public function add_condition_group() { 
    60  
    61         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    62         $group = absint( $_POST['group'] ); 
    63  
    64         ?><div class='wpc-condition-group wpc-condition-group-<?php echo $group; ?>' data-group='<?php echo $group; ?>'> 
    65  
    66             <p class='or-match'><?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></p><?php 
    67  
    68             $wp_condition = new WAFS_Condition( null, $group ); 
    69             $wp_condition->output_condition_row(); 
    70  
    71         ?></div> 
    72  
    73         <p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php 
    74  
    75         die(); 
    7624 
    7725    } 
     
    9240        $value_field_args = $wp_condition->get_value_field_args(); 
    9341 
    94         ?><span class='wpc-value-wrap wpc-value-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
     42        ?><span class='wpc-value-field-wrap'><?php 
    9543            wpc_html_field( $value_field_args ); 
    9644        ?></span><?php 
     
    10149 
    10250 
    103     /** 
    104      * Update description. 
    105      * 
    106      * Render the corresponding description for the condition key. 
    107      * 
    108      * @since 1.0.0 
    109      */ 
    110     public function update_condition_description() { 
    111  
    112         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    113  
    114         $condition    = sanitize_text_field( $_POST['condition'] ); 
    115         $wp_condition = new WAFS_Condition( null, null, $condition ); 
    116  
    117         if ( $desc = $wp_condition->get_description() ) { 
    118             ?><span class='wpc-description wpc-no-description <?php echo $desc; ?>-description'><?php 
    119             die(); 
    120         } 
    121  
    122         ?><span class='wpc-description <?php echo $wp_condition->condition; ?>-description'> 
    123             <img class='help_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' data-tip="<?php echo esc_html( $wp_condition->get_description() ); ?>" /> 
    124         </span><?php 
    125  
    126         die(); 
    127  
    128     } 
    129  
    130  
    13151} 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/class-wafs-match-conditions.php

    r1490367 r1609491  
    2020     */ 
    2121    public function __construct() { 
    22  
    23         add_filter( 'wafs_match_condition_subtotal', array( $this, 'wafs_match_condition_subtotal' ), 10, 3 ); 
    24         add_filter( 'wafs_match_condition_subtotal_ex_tax', array( $this, 'wafs_match_condition_subtotal_ex_tax' ), 10, 3 ); 
    25         add_filter( 'wafs_match_condition_tax', array( $this, 'wafs_match_condition_tax' ), 10, 3 ); 
    26         add_filter( 'wafs_match_condition_quantity', array( $this, 'wafs_match_condition_quantity' ), 10, 3 ); 
    27         add_filter( 'wafs_match_condition_contains_product', array( $this, 'wafs_match_condition_contains_product' ), 10, 3 ); 
    28         add_filter( 'wafs_match_condition_coupon', array( $this, 'wafs_match_condition_coupon' ), 10, 3 ); 
    29         add_filter( 'wafs_match_condition_weight', array( $this, 'wafs_match_condition_weight' ), 10, 3 ); 
    30         add_filter( 'wafs_match_condition_contains_shipping_class', array( $this, 'wafs_match_condition_contains_shipping_class' ), 10, 3 ); 
    31  
    3222        add_filter( 'wafs_match_condition_zipcode', array( $this, 'wafs_match_condition_zipcode' ), 10, 3 ); 
    33         add_filter( 'wafs_match_condition_city', array( $this, 'wafs_match_condition_city' ), 10, 3 ); 
    34         add_filter( 'wafs_match_condition_state', array( $this, 'wafs_match_condition_state' ), 10, 3 ); 
    35         add_filter( 'wafs_match_condition_country', array( $this, 'wafs_match_condition_country' ), 10, 3 ); 
    36         add_filter( 'wafs_match_condition_role', array( $this, 'wafs_match_condition_role' ), 10, 3 ); 
    37  
    38         add_filter( 'wafs_match_condition_width', array( $this, 'wafs_match_condition_width' ), 10, 3 ); 
    39         add_filter( 'wafs_match_condition_height', array( $this, 'wafs_match_condition_height' ), 10, 3 ); 
    40         add_filter( 'wafs_match_condition_length', array( $this, 'wafs_match_condition_length' ), 10, 3 ); 
    41         add_filter( 'wafs_match_condition_stock', array( $this, 'wafs_match_condition_stock' ), 10, 3 ); 
    42         add_filter( 'wafs_match_condition_stock_status', array( $this, 'wafs_match_condition_stock_status' ), 10, 3 ); 
    43         add_filter( 'wafs_match_condition_category', array( $this, 'wafs_match_condition_category' ), 10, 3 ); 
    44  
    4523    } 
    46  
    47  
    48     /** 
    49      * Subtotal. 
    50      * 
    51      * Match the condition value against the cart subtotal. 
    52      * 
    53      * @since 1.0.0 
    54      * 
    55      * @param   bool    $match     Current match value. 
    56      * @param   string  $operator  Operator selected by the user in the condition row. 
    57      * @param   mixed   $value     Value given by the user in the condition row. 
    58      * @return  bool               Matching result, true if results match, otherwise false. 
    59      */ 
    60     public function wafs_match_condition_subtotal( $match, $operator, $value ) { 
    61  
    62         if ( ! isset( WC()->cart ) ) return $match; 
    63  
    64         if ( '==' == $operator ) : 
    65             $match = ( WC()->cart->subtotal == $value ); 
    66         elseif ( '!=' == $operator ) : 
    67             $match = ( WC()->cart->subtotal != $value ); 
    68         elseif ( '>=' == $operator ) : 
    69             $match = ( WC()->cart->subtotal >= $value ); 
    70         elseif ( '<=' == $operator ) : 
    71             $match = ( WC()->cart->subtotal <= $value ); 
    72         endif; 
    73  
    74         return $match; 
    75  
    76     } 
    77  
    78  
    79     /** 
    80      * Subtotal excl. taxes. 
    81      * 
    82      * Match the condition value against the cart subtotal excl. taxes. 
    83      * 
    84      * @since 1.0.0 
    85      * 
    86      * @param   bool    $match     Current match value. 
    87      * @param   string  $operator  Operator selected by the user in the condition row. 
    88      * @param   mixed   $value     Value given by the user in the condition row. 
    89      * @return  bool               Matching result, true if results match, otherwise false. 
    90      */ 
    91     public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) { 
    92  
    93         if ( ! isset( WC()->cart ) ) return $match; 
    94  
    95         if ( '==' == $operator ) : 
    96             $match = ( WC()->cart->subtotal_ex_tax == $value ); 
    97         elseif ( '!=' == $operator ) : 
    98             $match = ( WC()->cart->subtotal_ex_tax != $value ); 
    99         elseif ( '>=' == $operator ) : 
    100             $match = ( WC()->cart->subtotal_ex_tax >= $value ); 
    101         elseif ( '<=' == $operator ) : 
    102             $match = ( WC()->cart->subtotal_ex_tax <= $value ); 
    103         endif; 
    104  
    105         return $match; 
    106  
    107     } 
    108  
    109  
    110     /** 
    111      * Taxes. 
    112      * 
    113      * Match the condition value against the cart taxes. 
    114      * 
    115      * @since 1.0.0 
    116      * 
    117      * @param   bool    $match     Current match value. 
    118      * @param   string  $operator  Operator selected by the user in the condition row. 
    119      * @param   mixed   $value     Value given by the user in the condition row. 
    120      * @return  bool               Matching result, true if results match, otherwise false. 
    121      */ 
    122     public function wafs_match_condition_tax( $match, $operator, $value ) { 
    123  
    124         if ( ! isset( WC()->cart ) ) return $match; 
    125  
    126         $taxes = array_sum( (array) WC()->cart->taxes ); 
    127  
    128         if ( '==' == $operator ) : 
    129             $match = ( $taxes == $value ); 
    130         elseif ( '!=' == $operator ) : 
    131             $match = ( $taxes != $value ); 
    132         elseif ( '>=' == $operator ) : 
    133             $match = ( $taxes >= $value ); 
    134         elseif ( '<=' == $operator ) : 
    135             $match = ( $taxes <= $value ); 
    136         endif; 
    137  
    138         return $match; 
    139  
    140     } 
    141  
    142  
    143     /** 
    144      * Quantity. 
    145      * 
    146      * Match the condition value against the cart quantity. 
    147      * This also includes product quantities. 
    148      * 
    149      * @since 1.0.0 
    150      * 
    151      * @param   bool    $match     Current match value. 
    152      * @param   string  $operator  Operator selected by the user in the condition row. 
    153      * @param   mixed   $value     Value given by the user in the condition row. 
    154      * @return  bool               Matching result, true if results match, otherwise false. 
    155      */ 
    156     public function wafs_match_condition_quantity( $match, $operator, $value ) { 
    157  
    158         if ( ! isset( WC()->cart ) ) return $match; 
    159  
    160         if ( '==' == $operator ) : 
    161             $match = ( WC()->cart->cart_contents_count == $value ); 
    162         elseif ( '!=' == $operator ) : 
    163             $match = ( WC()->cart->cart_contents_count != $value ); 
    164         elseif ( '>=' == $operator ) : 
    165             $match = ( WC()->cart->cart_contents_count >= $value ); 
    166         elseif ( '<=' == $operator ) : 
    167             $match = ( WC()->cart->cart_contents_count <= $value ); 
    168         endif; 
    169  
    170         return $match; 
    171  
    172     } 
    173  
    174  
    175     /** 
    176      * Contains product. 
    177      * 
    178      * Matches if the condition value product is in the cart. 
    179      * 
    180      * @since 1.0.0 
    181      * 
    182      * @param   bool    $match     Current match value. 
    183      * @param   string  $operator  Operator selected by the user in the condition row. 
    184      * @param   mixed   $value     Value given by the user in the condition row. 
    185      * @return  bool               Matching result, true if results match, otherwise false. 
    186      */ 
    187     public function wafs_match_condition_contains_product( $match, $operator, $value ) { 
    188  
    189         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    190  
    191         $product_ids = array(); 
    192         foreach ( WC()->cart->cart_contents as $product ) : 
    193             $product_ids[] = $product['product_id']; 
    194         endforeach; 
    195  
    196         if ( '==' == $operator ) : 
    197             $match = ( in_array( $value, $product_ids ) ); 
    198         elseif ( '!=' == $operator ) : 
    199             $match = ( ! in_array( $value, $product_ids ) ); 
    200         endif; 
    201  
    202         return $match; 
    203  
    204     } 
    205  
    206  
    207     /** 
    208      * Coupon. 
    209      * 
    210      * Match the condition value against the applied coupons. 
    211      * 
    212      * @since 1.0.0 
    213      * 
    214      * @param   bool    $match     Current match value. 
    215      * @param   string  $operator  Operator selected by the user in the condition row. 
    216      * @param   mixed   $value     Value given by the user in the condition row. 
    217      * @return  bool               Matching result, true if results match, otherwise false. 
    218      */ 
    219     public function wafs_match_condition_coupon( $match, $operator, $value ) { 
    220  
    221         if ( ! isset( WC()->cart ) ) : 
    222             return $match; 
    223         endif; 
    224  
    225         $coupons = array( 'percent' => array(), 'fixed' => array() ); 
    226         foreach ( WC()->cart->get_coupons() as $coupon ) { 
    227             $type               = str_replace( '_product', '', $coupon->discount_type ); 
    228             $type               = str_replace( '_cart', '', $type ); 
    229             $coupons[ $type ][] = $coupon->coupon_amount; 
    230         } 
    231  
    232         // Match against coupon percentage 
    233         if ( strpos( $value, '%' ) !== false ) { 
    234  
    235             $percentage_value = str_replace( '%', '', $value ); 
    236             if ( '==' == $operator ) : 
    237                 $match = in_array( $percentage_value, $coupons['percent'] ); 
    238             elseif ( '!=' == $operator ) : 
    239                 $match = ! in_array( $percentage_value, $coupons['percent'] ); 
    240             elseif ( '>=' == $operator ) : 
    241                 $match = empty( $coupons['percent'] ) ? $match : ( min( $coupons['percent'] ) >= $percentage_value ); 
    242             elseif ( '<=' == $operator ) : 
    243                 $match = ! is_array( $coupons['percent'] ) ? false : ( max( $coupons['percent'] ) <= $percentage_value ); 
    244             endif; 
    245  
    246             // Match against coupon amount 
    247         } elseif( strpos( $value, '$' ) !== false ) { 
    248  
    249             $amount_value = str_replace( '$', '', $value ); 
    250             if ( '==' == $operator ) : 
    251                 $match = in_array( $amount_value, $coupons['fixed'] ); 
    252             elseif ( '!=' == $operator ) : 
    253                 $match = ! in_array( $amount_value, $coupons['fixed'] ); 
    254             elseif ( '>=' == $operator ) : 
    255                 $match = empty( $coupons['fixed'] ) ? $match : ( min( $coupons['fixed'] ) >= $amount_value ); 
    256             elseif ( '<=' == $operator ) : 
    257                 $match = ! is_array( $coupons['fixed'] ) ? $match : ( max( $coupons['fixed'] ) <= $amount_value ); 
    258             endif; 
    259  
    260             // Match coupon codes 
    261         } else { 
    262  
    263             if ( '==' == $operator ) : 
    264                 $match = ( in_array( $value, WC()->cart->applied_coupons ) ); 
    265             elseif ( '!=' == $operator ) : 
    266                 $match = ( ! in_array( $value, WC()->cart->applied_coupons ) ); 
    267             endif; 
    268  
    269         } 
    270  
    271         return $match; 
    272  
    273     } 
    274  
    275  
    276     /** 
    277      * Weight. 
    278      * 
    279      * Match the condition value against the cart weight. 
    280      * 
    281      * @since 1.0.0 
    282      * 
    283      * @param   bool    $match     Current match value. 
    284      * @param   string  $operator  Operator selected by the user in the condition row. 
    285      * @param   mixed   $value     Value given by the user in the condition row. 
    286      * @return  bool               Matching result, true if results match, otherwise false. 
    287      */ 
    288     public function wafs_match_condition_weight( $match, $operator, $value ) { 
    289  
    290         if ( ! isset( WC()->cart ) ) return $match; 
    291  
    292         if ( '==' == $operator ) : 
    293             $match = ( WC()->cart->cart_contents_weight == $value ); 
    294         elseif ( '!=' == $operator ) : 
    295             $match = ( WC()->cart->cart_contents_weight != $value ); 
    296         elseif ( '>=' == $operator ) : 
    297             $match = ( WC()->cart->cart_contents_weight >= $value ); 
    298         elseif ( '<=' == $operator ) : 
    299             $match = ( WC()->cart->cart_contents_weight <= $value ); 
    300         endif; 
    301  
    302         return $match; 
    303  
    304     } 
    305  
    306  
    307     /** 
    308      * Shipping class. 
    309      * 
    310      * Matches if the condition value shipping class is in the cart. 
    311      * 
    312      * @since 1.1.0 
    313      * 
    314      * @param   bool    $match     Current match value. 
    315      * @param   string  $operator  Operator selected by the user in the condition row. 
    316      * @param   mixed   $value     Value given by the user in the condition row. 
    317      * @return  bool               Matching result, true if results match, otherwise false. 
    318      */ 
    319     public function wafs_match_condition_contains_shipping_class( $match, $operator, $value ) { 
    320  
    321         if ( ! isset( WC()->cart ) ) return $match; 
    322  
    323         // True until proven false 
    324         if ( $operator == '!=' ) : 
    325             $match = true; 
    326         endif; 
    327  
    328         foreach ( WC()->cart->cart_contents as $product ) : 
    329  
    330             $id      = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id']; 
    331             $product = wc_get_product( $id ); 
    332  
    333             if ( $operator == '==' ) : 
    334                 if ( $product->get_shipping_class() == $value ) : 
    335                     return true; 
    336                 endif; 
    337             elseif ( $operator == '!=' ) : 
    338                 if ( $product->get_shipping_class() == $value ) : 
    339                     return false; 
    340                 endif; 
    341             endif; 
    342  
    343         endforeach; 
    344  
    345         return $match; 
    346  
    347     } 
    348  
    349  
    350 /****************************************************** 
    351  * User conditions 
    352  *****************************************************/ 
    35324 
    35425 
     
    451122 
    452123 
    453     /** 
    454      * City. 
    455      * 
    456      * Match the condition value against the users shipping city. 
    457      * 
    458      * @since 1.0.0 
    459      * 
    460      * @param   bool    $match     Current match value. 
    461      * @param   string  $operator  Operator selected by the user in the condition row. 
    462      * @param   mixed   $value     Value given by the user in the condition row. 
    463      * @return  bool               Matching result, true if results match, otherwise false. 
    464      */ 
    465     public function wafs_match_condition_city( $match, $operator, $value ) { 
    466  
    467         if ( ! isset( WC()->customer ) ) return $match; 
    468  
    469         $customer_city = strtolower( WC()->customer->get_shipping_city() ); 
    470         $value         = strtolower( $value ); 
    471  
    472         if ( '==' == $operator ) : 
    473  
    474             if ( preg_match( '/\, ?/', $value ) ) : 
    475                 $match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) ); 
    476             else : 
    477                 $match = ( $value == $customer_city ); 
    478             endif; 
    479  
    480         elseif ( '!=' == $operator ) : 
    481  
    482             if ( preg_match( '/\, ?/', $value ) ) : 
    483                 $match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) ); 
    484             else : 
    485                 $match = ( $value == $customer_city ); 
    486             endif; 
    487  
    488         endif; 
    489  
    490         return $match; 
    491  
    492     } 
    493  
    494  
    495     /** 
    496      * State. 
    497      * 
    498      * Match the condition value against the users shipping state 
    499      * 
    500      * @since 1.0.0 
    501      * 
    502      * @param   bool    $match     Current match value. 
    503      * @param   string  $operator  Operator selected by the user in the condition row. 
    504      * @param   mixed   $value     Value given by the user in the condition row. 
    505      * @return  bool               Matching result, true if results match, otherwise false. 
    506      */ 
    507     public function wafs_match_condition_state( $match, $operator, $value ) { 
    508  
    509         if ( ! isset( WC()->customer ) ) return $match; 
    510  
    511         $state = WC()->customer->get_shipping_country() . '_' . WC()->customer->get_shipping_state(); 
    512  
    513         if ( '==' == $operator ) : 
    514             $match = ( $state == $value ); 
    515         elseif ( '!=' == $operator ) : 
    516             $match = ( $state != $value ); 
    517         endif; 
    518  
    519         return $match; 
    520  
    521     } 
    522  
    523  
    524     /** 
    525      * Country. 
    526      * 
    527      * Match the condition value against the users shipping country. 
    528      * 
    529      * @since 1.0.0 
    530      * 
    531      * @param   bool    $match     Current match value. 
    532      * @param   string  $operator  Operator selected by the user in the condition row. 
    533      * @param   mixed   $value     Value given by the user in the condition row. 
    534      * @return  bool               Matching result, true if results match, otherwise false. 
    535      */ 
    536     public function wafs_match_condition_country( $match, $operator, $value ) { 
    537  
    538         if ( ! isset( WC()->customer ) ) : 
    539             return $match; 
    540         endif; 
    541  
    542         $user_country = WC()->customer->get_shipping_country(); 
    543  
    544         if ( method_exists( WC()->countries, 'get_continent_code_for_country' ) ) : 
    545             $user_continent = WC()->countries->get_continent_code_for_country( $user_country ); 
    546         endif; 
    547  
    548         if ( '==' == $operator ) : 
    549             $match = stripos( $user_country, $value ) === 0; 
    550  
    551             // Check for continents if available 
    552             if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) : 
    553                 $match = stripos( $user_continent, str_replace( 'CO_','', $value ) ) === 0; 
    554             endif; 
    555         elseif ( '!=' == $operator ) : 
    556             $match = stripos( $user_country, $value ) === false; 
    557  
    558             // Check for continents if available 
    559             if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) : 
    560                 $match = stripos( $user_continent, str_replace( 'CO_','', $value ) ) === false; 
    561             endif; 
    562         endif; 
    563  
    564         return $match; 
    565  
    566     } 
    567  
    568  
    569     /** 
    570      * User role. 
    571      * 
    572      * Match the condition value against the users role. 
    573      * 
    574      * @since 1.0.0 
    575      * @global object $current_user Current user object for capabilities. 
    576      * 
    577      * @param   bool    $match     Current match value. 
    578      * @param   string  $operator  Operator selected by the user in the condition row. 
    579      * @param   mixed   $value     Value given by the user in the condition row. 
    580      * @return  bool               Matching result, true if results match, otherwise false. 
    581      */ 
    582     public function wafs_match_condition_role( $match, $operator, $value ) { 
    583  
    584         global $current_user; 
    585  
    586         if ( '==' == $operator ) : 
    587             $match = ( array_key_exists( $value, $current_user->caps ) ); 
    588         elseif ( '!=' == $operator ) : 
    589             $match = ( ! array_key_exists( $value, $current_user->caps ) ); 
    590         endif; 
    591  
    592         return $match; 
    593  
    594     } 
    595  
    596  
    597 /****************************************************** 
    598  * Product conditions 
    599  *****************************************************/ 
    600  
    601  
    602     /** 
    603      * Width. 
    604      * 
    605      * Match the condition value against the widest product in the cart. 
    606      * 
    607      * @since 1.0.0 
    608      * 
    609      * @param   bool    $match     Current match value. 
    610      * @param   string  $operator  Operator selected by the user in the condition row. 
    611      * @param   mixed   $value     Value given by the user in the condition row. 
    612      * @return  bool               Matching result, true if results match, otherwise false. 
    613      */ 
    614     public function wafs_match_condition_width( $match, $operator, $value ) { 
    615  
    616         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    617  
    618         foreach ( WC()->cart->cart_contents as $product ) : 
    619  
    620             if ( true == $product['data']->variation_has_width ) : 
    621                 $width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) ); 
    622             else : 
    623                 $width[] = ( get_post_meta( $product['product_id'], '_width', true ) ); 
    624             endif; 
    625  
    626         endforeach; 
    627  
    628         $max_width = max( (array) $width ); 
    629  
    630         if ( '==' == $operator ) : 
    631             $match = ( $max_width == $value ); 
    632         elseif ( '!=' == $operator ) : 
    633             $match = ( $max_width != $value ); 
    634         elseif ( '>=' == $operator ) : 
    635             $match = ( $max_width >= $value ); 
    636         elseif ( '<=' == $operator ) : 
    637             $match = ( $max_width <= $value ); 
    638         endif; 
    639  
    640         return $match; 
    641  
    642     } 
    643  
    644  
    645     /** 
    646      * Height. 
    647      * 
    648      * Match the condition value against the highest product in the cart. 
    649      * 
    650      * @since 1.0.0 
    651      * 
    652      * @param   bool    $match     Current match value. 
    653      * @param   string  $operator  Operator selected by the user in the condition row. 
    654      * @param   mixed   $value     Value given by the user in the condition row. 
    655      * @return  bool               Matching result, true if results match, otherwise false. 
    656      */ 
    657     public function wafs_match_condition_height( $match, $operator, $value ) { 
    658  
    659         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    660  
    661         foreach ( WC()->cart->cart_contents as $product ) : 
    662  
    663             if ( true == $product['data']->variation_has_height ) : 
    664                 $height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) ); 
    665             else : 
    666                 $height[] = ( get_post_meta( $product['product_id'], '_height', true ) ); 
    667             endif; 
    668  
    669         endforeach; 
    670  
    671         $max_height = max( $height ); 
    672  
    673         if ( '==' == $operator ) : 
    674             $match = ( $max_height == $value ); 
    675         elseif ( '!=' == $operator ) : 
    676             $match = ( $max_height != $value ); 
    677         elseif ( '>=' == $operator ) : 
    678             $match = ( $max_height >= $value ); 
    679         elseif ( '<=' == $operator ) : 
    680             $match = ( $max_height <= $value ); 
    681         endif; 
    682  
    683         return $match; 
    684  
    685     } 
    686  
    687  
    688     /** 
    689      * Length. 
    690      * 
    691      * Match the condition value against the lenghtiest product in the cart. 
    692      * 
    693      * @since 1.0.0 
    694      * 
    695      * @param   bool    $match     Current match value. 
    696      * @param   string  $operator  Operator selected by the user in the condition row. 
    697      * @param   mixed   $value     Value given by the user in the condition row. 
    698      * @return  bool               Matching result, true if results match, otherwise false. 
    699      */ 
    700     public function wafs_match_condition_length( $match, $operator, $value ) { 
    701  
    702         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    703  
    704         foreach ( WC()->cart->cart_contents as $product ) : 
    705  
    706             if ( true == $product['data']->variation_has_length ) : 
    707                 $length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) ); 
    708             else : 
    709                 $length[] = ( get_post_meta( $product['product_id'], '_length', true ) ); 
    710             endif; 
    711  
    712         endforeach; 
    713  
    714         $max_length = max( $length ); 
    715  
    716         if ( '==' == $operator ) : 
    717             $match = ( $max_length == $value ); 
    718         elseif ( '!=' == $operator ) : 
    719             $match = ( $max_length != $value ); 
    720         elseif ( '>=' == $operator ) : 
    721             $match = ( $max_length >= $value ); 
    722         elseif ( '<=' == $operator ) : 
    723             $match = ( $max_length <= $value ); 
    724         endif; 
    725  
    726         return $match; 
    727  
    728     } 
    729  
    730  
    731     /** 
    732      * Product stock. 
    733      * 
    734      * Match the condition value against all cart products stock. 
    735      * 
    736      * @since 1.0.0 
    737      * 
    738      * @param   bool    $match     Current match value. 
    739      * @param   string  $operator  Operator selected by the user in the condition row. 
    740      * @param   mixed   $value     Value given by the user in the condition row. 
    741      * @return  bool               Matching result, true if results match, otherwise false. 
    742      */ 
    743     public function wafs_match_condition_stock( $match, $operator, $value ) { 
    744  
    745         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    746  
    747         foreach ( WC()->cart->cart_contents as $product ) : 
    748  
    749             $product_id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id']; 
    750             $stock[]    = get_post_meta( $product_id, '_stock', true ); 
    751  
    752         endforeach; 
    753  
    754         $min_stock = min( $stock ); 
    755  
    756         if ( '==' == $operator ) : 
    757             $match = ( $min_stock == $value ); 
    758         elseif ( '!=' == $operator ) : 
    759             $match = ( $min_stock != $value ); 
    760         elseif ( '>=' == $operator ) : 
    761             $match = ( $min_stock >= $value ); 
    762         elseif ( '<=' == $operator ) : 
    763             $match = ( $min_stock <= $value ); 
    764         endif; 
    765  
    766         return $match; 
    767  
    768     } 
    769  
    770  
    771     /** 
    772      * Stock status. 
    773      * 
    774      * Match the condition value against all cart products stock statuses. 
    775      * 
    776      * @since 1.0.0 
    777      * 
    778      * @param   bool    $match     Current match value. 
    779      * @param   string  $operator  Operator selected by the user in the condition row. 
    780      * @param   mixed   $value     Value given by the user in the condition row. 
    781      * @return  bool               Matching result, true if results match, otherwise false. 
    782      */ 
    783     public function wafs_match_condition_stock_status( $match, $operator, $value ) { 
    784  
    785         if ( ! isset( WC()->cart ) ) return $match; 
    786  
    787         if ( '==' == $operator ) : 
    788  
    789             $match = true; 
    790             foreach ( WC()->cart->cart_contents as $product ) : 
    791                 if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value ) { 
    792                     $match = false; 
    793                 } 
    794             endforeach; 
    795  
    796         elseif ( '!=' == $operator ) : 
    797  
    798             $match = true; 
    799             foreach ( WC()->cart->cart_contents as $product ) : 
    800                 if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value ) { 
    801                     $match = false; 
    802                 } 
    803             endforeach; 
    804  
    805         endif; 
    806  
    807         return $match; 
    808  
    809     } 
    810  
    811  
    812     /** 
    813      * Category. 
    814      * 
    815      * Match the condition value against all the cart products category. 
    816      * With this condition, all the products in the cart must have the given class. 
    817      * 
    818      * @since 1.0.0 
    819      * 
    820      * @param   bool    $match     Current match value. 
    821      * @param   string  $operator  Operator selected by the user in the condition row. 
    822      * @param   mixed   $value     Value given by the user in the condition row. 
    823      * @return  bool               Matching result, true if results match, otherwise false. 
    824      */ 
    825     public function wafs_match_condition_category( $match, $operator, $value ) { 
    826  
    827         if ( ! isset( WC()->cart ) ) return $match; 
    828  
    829         $match = true; 
    830  
    831         if ( '==' == $operator ) : 
    832  
    833             foreach ( WC()->cart->cart_contents as $product ) : 
    834  
    835                 if ( ! has_term( $value, 'product_cat', $product['product_id'] ) ) : 
    836                     $match = false; 
    837                 endif; 
    838  
    839             endforeach; 
    840  
    841         elseif ( '!=' == $operator ) : 
    842  
    843             foreach ( WC()->cart->cart_contents as $product ) : 
    844  
    845                 if ( has_term( $value, 'product_cat', $product['product_id'] ) ) : 
    846                     $match = false; 
    847                 endif; 
    848  
    849             endforeach; 
    850  
    851         endif; 
    852  
    853         return $match; 
    854  
    855     } 
    856  
    857  
    858124} 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/class-wafs-method.php

    r1483190 r1609491  
    1919        $this->method_title       = __( 'Advanced Free Shipping', 'woocommerce-advanced-free-shipping' ); 
    2020        $this->method_description = __( 'Configure Advanced Free Shipping' ); 
    21  
    22         $this->matched_methods = $this->wafs_match_methods(); 
    2321 
    2422        $this->init(); 
     
    6462        $methods = wafs_get_rates(); 
    6563 
    66         $matched_methods = ''; 
     64        $matched_methods = false; 
    6765        foreach ( $methods as $method ) : 
    6866 
    6967            $condition_groups = get_post_meta( $method->ID, '_wafs_shipping_method_conditions', true ); 
    7068 
    71             // Check if method conditions match 
    72             $match = $this->wafs_match_conditions( $condition_groups ); 
    73  
    74             // Add (single) match to parameter 
    75             if ( true == $match ) : 
     69            // Check if conditions match 
     70            if ( wpc_match_conditions( $condition_groups, array( 'context' => 'wafs' ) ) ) : 
    7671                $matched_methods = $method->ID; 
    7772            endif; 
     
    8075 
    8176        return $matched_methods; 
    82  
    83     } 
    84  
    85  
    86     /** 
    87      * Match conditions. 
    88      * 
    89      * Method to check all condition groups and conditions if they match their rules. 
    90      * 
    91      * @since 1.0.0 
    92      * 
    93      * @param   array  $condition_groups  All condition groups set by the user. 
    94      * @return  bool                      true if one of the conditions groups matches. 
    95      */ 
    96     public function wafs_match_conditions( $condition_groups = array() ) { 
    97  
    98         if ( empty( $condition_groups ) ) return false; 
    99  
    100         foreach ( $condition_groups as $condition_group => $conditions ) : 
    101  
    102             $match_condition_group = true; 
    103  
    104             foreach ( $conditions as $condition ) : 
    105  
    106                 $match = apply_filters( 'wafs_match_condition_' . $condition['condition'], false, $condition['operator'], $condition['value'] ); 
    107  
    108                 if ( false == $match ) : 
    109                     $match_condition_group = false; 
    110                 endif; 
    111  
    112             endforeach; 
    113  
    114             // return true if one condition group matches 
    115             if ( true == $match_condition_group ) : 
    116                 return true; 
    117             endif; 
    118  
    119         endforeach; 
    120  
    121         return false; 
    12277 
    12378    } 
     
    166121 
    167122        ob_start(); 
    168  
    169             /** 
    170              * Load conditions table file 
    171              */ 
    172123            require_once plugin_dir_path( __FILE__ ) . 'admin/views/conditions-table.php'; 
    173  
    174124        return ob_get_clean(); 
    175  
    176     } 
    177  
    178  
    179     /** 
    180      * Validate table. 
    181      * 
    182      * Condition table does not need validation, so always return false. 
    183      * 
    184      * @since 1.0.0 
    185      * 
    186      * @param   mixed  $key  Key. 
    187      * @return  bool         Validation. 
    188      */ 
    189     public function validate_additional_conditions_table_field( $key ) { 
    190  
    191         return false; 
    192125 
    193126    } 
     
    205138    public function calculate_shipping( $package = array() ) { 
    206139 
    207         if ( false == $this->matched_methods || 'no' == $this->enabled ) return; 
     140        if ( $this->enabled == 'no' ) { 
     141            return; 
     142        } 
    208143 
    209         $method_args = get_post_meta( $this->matched_methods, '_wafs_shipping_method', true ); 
     144        if ( ! $matched_rate = $this->wafs_match_methods() ) { 
     145            return; 
     146        } 
     147 
     148        $method_args = get_post_meta( $matched_rate, '_wafs_shipping_method', true ); 
    210149        $label       = ! empty( $method_args['shipping_title'] ) ? $method_args['shipping_title'] : __( 'Free Shipping', 'woocommerce-advanced-free-shipping' ); 
    211150 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/class-wafs-post-type.php

    r1483190 r1609491  
    2727        add_action( 'add_meta_boxes', array( $this, 'post_type_meta_box' ) ); 
    2828        add_action( 'save_post', array( $this, 'save_meta' ) ); 
    29         add_action( 'save_post', array( $this, 'save_condition_meta' ) ); 
    3029 
    3130        // Edit user messages 
     
    4847 
    4948        $labels = array( 
    50             'name'               => __( 'Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ), 
    51             'singular_name'      => __( 'Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
     49            'name'               => __( 'Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ), 
     50            'singular_name'      => __( 'Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
    5251            'add_new'            => __( 'Add New', 'woocommerce-advanced-free-shipping' ), 
    53             'add_new_item'       => __( 'Add New Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
    54             'edit_item'          => __( 'Edit Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
    55             'new_item'           => __( 'New Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
    56             'view_item'          => __( 'View Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
    57             'search_items'       => __( 'Search Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ), 
    58             'not_found'          => __( 'No Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ), 
    59             'not_found_in_trash' => __( 'No Advanced Free Shipping methods found in Trash', 'woocommerce-advanced-free-shipping' ), 
     52            'add_new_item'       => __( 'Add New Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
     53            'edit_item'          => __( 'Edit Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
     54            'new_item'           => __( 'New Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
     55            'view_item'          => __( 'View Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
     56            'search_items'       => __( 'Search Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ), 
     57            'not_found'          => __( 'No Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ), 
     58            'not_found_in_trash' => __( 'No Advanced Free Shipping rates found in Trash', 'woocommerce-advanced-free-shipping' ), 
    6059        ); 
    6160 
     
    9594        $messages['wafs'] = array( 
    9695            0  => '', 
    97             1  => __( 'Free shipping method updated.', 'woocommerce-advanced-free-shipping' ), 
     96            1  => __( 'Free shipping rate updated.', 'woocommerce-advanced-free-shipping' ), 
    9897            2  => __( 'Custom field updated.', 'woocommerce-advanced-free-shipping' ), 
    9998            3  => __( 'Custom field deleted.', 'woocommerce-advanced-free-shipping' ), 
    100             4  => __( 'Free shipping method updated.', 'woocommerce-advanced-free-shipping' ), 
    101             6  => __( 'Free shipping method published.', 'woocommerce-advanced-free-shipping' ), 
    102             7  => __( 'Free shipping method saved.', 'woocommerce-advanced-free-shipping' ), 
    103             8  => __( 'Free shipping method submitted.', 'woocommerce-advanced-free-shipping' ), 
     99            4  => __( 'Free shipping rate updated.', 'woocommerce-advanced-free-shipping' ), 
     100            6  => __( 'Free shipping rate published.', 'woocommerce-advanced-free-shipping' ), 
     101            7  => __( 'Free shipping rate saved.', 'woocommerce-advanced-free-shipping' ), 
     102            8  => __( 'Free shipping rate submitted.', 'woocommerce-advanced-free-shipping' ), 
    104103            9  => sprintf( 
    105104                __( 'Free shipping method scheduled for: <strong>%1$s</strong>.', 'woocommerce-advanced-free-shipping' ), 
    106105                date_i18n( __( 'M j, Y @ G:i', 'woocommerce-advanced-free-shipping' ), strtotime( $post->post_date ) ) 
    107106            ), 
    108             10 => __( 'Free shipping method draft updated.', 'woocommerce-advanced-free-shipping' ), 
     107            10 => __( 'Free shipping rate draft updated.', 'woocommerce-advanced-free-shipping' ), 
    109108        ); 
    110109 
    111110        if ( 'wafs' == $post_type ) : 
    112             $overview_link = admin_url( 'admin.php?page=wc-settings&tab=shipping&section=wafs_free_shipping_method' ); 
     111            $overview_link = admin_url( 'admin.php?page=wc-settings&tab=shipping&section=advanced_free_shipping' ); 
    113112 
    114113            $overview                    = sprintf( ' <a href="%s">%s</a>', esc_url( $overview_link ), __( 'Return to overview.', 'woocommerce-advanced-free-shipping' ) ); 
     
    149148     */ 
    150149    public function render_wafs_conditions() { 
    151  
    152         /** 
    153          * Load meta box conditions view. 
    154          */ 
    155150        require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-conditions.php'; 
    156  
    157151    } 
    158152 
     
    166160     */ 
    167161    public function render_wafs_settings() { 
    168  
    169         /** 
    170          * Load meta box settings view 
    171          */ 
    172162        require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-settings.php'; 
    173  
    174     } 
    175  
    176  
    177     /** 
    178      * Save conditions meta box. 
    179      * 
    180      * Validate and save post meta from conditions meta box. 
    181      * 
    182      * @since 1.0.0 
    183      */ 
    184     public function save_condition_meta( $post_id ) { 
     163    } 
     164 
     165 
     166    /** 
     167     * Save settings meta box. 
     168     * 
     169     * Validate and save post meta from settings meta box. 
     170     * 
     171     * @since 1.0.0 
     172     */ 
     173    public function save_meta( $post_id ) { 
    185174 
    186175        if ( ! isset( $_POST['wafs_settings_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['wafs_settings_meta_box_nonce'], 'wafs_settings_meta_box' ) ) : 
     
    196185        endif; 
    197186 
    198         $shipping_method_conditions = $_POST['conditions']; 
    199  
    200         update_post_meta( $post_id, '_wafs_shipping_method_conditions', $shipping_method_conditions ); 
    201  
    202     } 
    203  
    204  
    205     /** 
    206      * Save settings meta box. 
    207      * 
    208      * Validate and save post meta from settings meta box. 
    209      * 
    210      * @since 1.0.0 
    211      */ 
    212     public function save_meta( $post_id ) { 
    213  
    214         if ( ! isset( $_POST['wafs_settings_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['wafs_settings_meta_box_nonce'], 'wafs_settings_meta_box' ) ) : 
    215             return $post_id; 
    216         endif; 
    217  
    218         if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) : 
    219             return $post_id; 
    220         endif; 
    221  
    222         if ( ! current_user_can( 'manage_woocommerce' ) ) : 
    223             return $post_id; 
    224         endif; 
    225  
    226187        $shipping_method = array_map( 'sanitize_text_field', $_POST['_wafs_shipping_method'] ); 
    227  
    228188        update_post_meta( $post_id, '_wafs_shipping_method', $shipping_method ); 
     189 
     190        // Save sanitized conditions 
     191        update_post_meta( $post_id, '_wafs_shipping_method_conditions', wpc_sanitize_conditions( $_POST['conditions'] ) ); 
    229192 
    230193    } 
  • woocommerce-advanced-free-shipping/tags/1.1.0/includes/core-functions.php

    r1483190 r1609491  
    2020        'orderby'                => 'menu_order', 
    2121        'order'                  => 'ASC', 
    22         'update_post_term_cache' => false 
     22        'update_post_term_cache' => false, 
     23        'no_found_rows'          => true, 
    2324    ) ); 
    2425 
    2526    $rates_query    = new WP_Query( $query_args ); 
    26     $shipping_rates = $rates_query->get_posts(); 
     27    $shipping_rates = $rates_query->posts; 
    2728 
    2829    return apply_filters( 'woocommerce_advanced_free_shipping_get_rates', $shipping_rates ); 
    2930 
    3031} 
     32 
     33/************************************************************** 
     34 * Backwards compatibility for WP Conditions 
     35 *************************************************************/ 
     36 
     37/** 
     38 * Add the filters required for backwards-compatibility for the matching functionality. 
     39 * 
     40 * @since 1.1.0 
     41 */ 
     42function wafs_add_bc_filter_condition_match( $match, $condition, $operator, $value, $args = array() ) { 
     43 
     44    if ( ! isset( $args['context'] ) || $args['context'] != 'wafs' ) { 
     45        return $match; 
     46    } 
     47 
     48    if ( has_filter( 'wafs_match_condition_' . $condition ) ) { 
     49        $match = apply_filters( 'wafs_match_condition_' . $condition, $match = false, $operator, $value ); 
     50    } 
     51 
     52    return $match; 
     53 
     54} 
     55add_action( 'wp-conditions\condition\match', 'wafs_add_bc_filter_condition_match', 10, 5 ); 
     56 
     57 
     58/** 
     59 * Add condition descriptions of custom conditions. 
     60 * 
     61 * @since 1.1.0 
     62 */ 
     63function wafs_add_bc_filter_condition_descriptions( $descriptions ) { 
     64    return apply_filters( 'wafs_descriptions', $descriptions ); 
     65} 
     66add_filter( 'wp-conditions\condition_descriptions', 'wafs_add_bc_filter_condition_descriptions' ); 
     67 
     68 
     69/** 
     70 * Add custom field BC. 
     71 * 
     72 * @since 1.1.0 
     73 */ 
     74function wafs_add_bc_action_custom_fields( $type, $args ) { 
     75 
     76    if ( has_action( 'woocommerce_advanced_fees_condition_value_field_type_' . $type ) ) { 
     77        do_action( 'woocommerce_advanced_fees_condition_value_field_type_' . $args['type'], $args ); 
     78    } 
     79 
     80} 
     81add_action( 'wp-conditions\html_field_hook', 'wafs_add_bc_action_custom_fields' ); 
  • woocommerce-advanced-free-shipping/tags/1.1.0/readme.txt

    r1491641 r1609491  
    33Tags: woocommerce, shipping, woocommerce shipping, woocommerce free shipping, woocommerce free, woocommerce advanced free shipping, wc free shipping, wc shipping, advanced shipping, pro shipping, table rate shipping, country shipping, free shipping 
    44Requires at least: 4.0 
    5 Tested up to: 4.6 
    6 Stable tag: 1.0.11 
     5Tested up to: 4.7.2 
     6Stable tag: 1.1.0 
    77License: GPLv3 or later 
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html 
     
    1515*Conditions like:* 
    1616 
    17 - Cart total 
     17- Subtotal 
     18- User role 
    1819- Country 
    1920- Zip code 
     
    4546> View [WooCommerce Advanced Shipping](http://codecanyon.net/item/woocommerce-advanced-shipping/8634573) 
    4647 
    47 **Translations, feature requests, ratings and donations are welcome and appreciated!** 
     48**Showing a free shipping threshold message** 
     49There are a few plugins out there that add a message when someone hasn't reached the free shipping threshold yet. These plugin work on the 'Free shipping' option that is provided in WooCommerce by default. 
     50It is unlikely that these plugins will work out of the box with Advanced Free Shipping due to the complexity of the conditional logic. 
     51 
     52In case you do want to show this kind of message, The [Advanced Messages for WooCommerce](https://shopplugins.com/plugins/woocommerce-advanced-messages/ ) plugin allows you to setup a message with the same type of conditions, allowing you to setup the messages according to the same needs as the free shipping options. 
     53 
     54**Translations, feature requests and ratings are welcome and appreciated!** 
    4855 
    4956**Translations** 
     
    6572 
    6673== Changelog == 
     74 
     75= 1.1.0 - 06-03-2017 = IMPORTANT NOTE - As of this version, the plugin requires PHP 5.3 to function 
     76 
     77* [Fix] - Allow variations to be set (and make them working) with the 'contains product' condition 
     78* [Fix] - Prevent duplicate DB query 
     79* [Improvement] - BIG refactor of the backend conditions - please verify your setup if using custom coded condition 
     80* [Improvement] - Smoother User Experience with conditions 
     81    - Instant adding of conditions / condition groups 
     82    - Only show valid operator options 
     83    - Instantly show condition descriptions 
     84    - Deleting entire condition groups 
     85    - Duplicate condition groups 
     86* [Improvement] - WC 2.7 compatibility changes 
    6787 
    6888= 1.0.11 - 05-09-2016 = 
  • woocommerce-advanced-free-shipping/tags/1.1.0/woocommerce-advanced-free-shipping.php

    r1490367 r1609491  
    44 * Plugin URI:      https://wordpress.org/plugins/woocommerce-advanced-free-shipping/ 
    55 * Description:     WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions. 
    6  * Version:         1.0.11 
     6 * Version:         1.1.0 
    77 * Author:          Jeroen Sormani 
    88 * Author URI:      http://jeroensormani.com/ 
     
    4949     * @var string $version Plugin version number. 
    5050     */ 
    51     public $version = '1.0.11'; 
     51    public $version = '1.1.0'; 
    5252 
    5353 
     
    8989        endif; 
    9090 
    91         $this->init(); 
    92  
    9391    } 
    9492 
     
    124122    public function init() { 
    125123 
     124        if ( version_compare( PHP_VERSION, '5.3', 'lt' ) ) { 
     125            return add_action( 'admin_notices', array( $this, 'php_version_notice' ) ); 
     126        } 
     127 
    126128        // Add hooks/filters 
    127129        $this->hooks(); 
     
    133135        $this->update(); 
    134136 
     137        require_once plugin_dir_path( __FILE__ ) . '/libraries/wp-conditions/functions.php'; 
     138 
    135139        // Functions 
    136140        require_once plugin_dir_path( __FILE__ ) . 'includes/core-functions.php'; 
     
    158162         */ 
    159163        if ( is_admin() ) : 
    160             require_once plugin_dir_path( __FILE__ ) . 'includes/admin/admin-functions.php'; 
    161  
    162164            require_once plugin_dir_path( __FILE__ ) . 'includes/admin/class-wafs-admin.php'; 
    163165            $this->admin = new WAFS_Admin(); 
     166            $this->admin->init(); 
    164167        endif; 
    165168 
     
    213216 
    214217        // Add shipping method 
    215         add_action( 'woocommerce_shipping_methods', array( $this, 'wafs_add_shipping_method' ) ); 
     218        add_filter( 'woocommerce_shipping_methods', array( $this, 'wafs_add_shipping_method' ) ); 
    216219 
    217220    } 
     
    270273 
    271274    /** 
    272      * Enqueue scripts. 
    273      * 
    274      * Enqueue javascript and stylesheets to the admin area. 
    275      * 
    276      * @since 1.0.0 
    277      */ 
    278     public function wafs_admin_enqueue_scripts() { 
    279  
    280         _deprecated_function( __FUNCTION__, '1.0.8', 'WAFS()->admin->admin_enqueue_script()' ); 
    281  
    282     } 
    283  
     275     * Display PHP 5.3 required notice. 
     276     * 
     277     * Display a notice when the required PHP version is not met. 
     278     * 
     279     * @since 1.0.6 
     280     */ 
     281    public function php_version_notice() { 
     282 
     283        ?><div class='updated'> 
     284        <p><?php echo sprintf( __( 'Advanced Free Shipping requires PHP 5.3 or higher and your current PHP version is %s. Please (contact your host to) update your PHP version.', 'woocommerce-advanced-messages' ), PHP_VERSION ); ?></p> 
     285        </div><?php 
     286 
     287    } 
    284288 
    285289} 
     
    308312endif; 
    309313 
    310 WAFS(); 
     314WAFS()->init(); 
  • woocommerce-advanced-free-shipping/trunk/assets/css/woocommerce-advanced-free-shipping.min.css

    r1490367 r1609491  
    1 .wpc-conditions .wpc-condition-group{margin-bottom:30px;background-color:#f5f5f5;padding:15px 20px 20px;border:1px solid #ddd;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04);min-height:30px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap{margin:10px 0 5px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-condition{width:30%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-operator{width:12%;min-width:140px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-value{width:30%;height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description{float:right}.wpc-conditions .wpc-condition-group .wpc-condition-wrap input{vertical-align:top}.wpc-conditions .or-text{display:none !important}.wpc-conditions .wpc-condition-group ~ .or-text,.wpc-conditions .wpc-condition-group ~ .or-text ~ .wpc-condition-group .or-text{display:block !important}.wpc-conditions .wpc-condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wpc-conditions .wpc-condition-wrap:hover .wpc-condition-delete{display:inline-block;opacity:1}.wpc-conditions .wpc-condition-wrap.loading{height:30px}.wpc-conditions .wpc-condition-wrap.loading .loading-icon{width:100%;clear:both;display:block;text-align:center;line-height:110%;margin:0 1px}.wpc-condition-wrap .wpc-value.select2-container{display:inline-block !important;margin:1px}.wpc-condition-wrap .wpc-value.select2-container.select2-container-active .select2-choice{border:1px solid #666}.wpc-condition-wrap .wpc-value.select2-container.select2-drop-above .select2-choice{border-radius:0 0 4px 4px;border:1px solid #666;border-top-color:transparent}.wpc-condition-wrap .wpc-value.select2-container .select2-choice{border-color:#ddd;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;height:26px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);box-shadow:inset 0 1px 2px rgba(0,0,0,0.07)}.wpc-condition-wrap .wpc-value.select2-dropdown-open .select2-choice{border-bottom-color:transparent;-webkit-box-shadow:0 1px 0 #fff inset;box-shadow:0 1px 0 #fff inset;border-bottom-left-radius:0;border-bottom-right-radius:0;border:1px solid #666;outline:0}.wpc-conditions-post-table .sort{padding:0 4px;cursor:move;text-align:center;vertical-align:middle}.wpc-conditions-post-table .sort:before{content:"\e032";font-family:WooCommerce;text-align:center;line-height:1;color:#999;display:block;width:100%;float:left;height:100%}.wpc-conditions-post-table .sort:before,.wpc-conditions-post-table .row-actions{visibility:hidden !important}.wpc-conditions-post-table tr:hover .sort:before,.wpc-conditions-post-table tr:hover>td>.row-actions{visibility:visible !important}.wpc-conditions-post-table .add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}.wpc-currency{padding:3px 10px;font-size:14px;font-weight:400;line-height:19px;height:27px;box-sizing:border-box;color:#555;text-align:center;background-color:#EEE;border:1px solid #DDD;border-right:none;border-radius:4px 0px 0px 4px;margin:1px 0px 1px 1px;display:inline-block}.wpc-currency+input{margin-left:-4px;line-height:19px;width:161px !important}.post-type-wafs .misc-pub-visibility#visibility{display:none}.wafs-option label{display:inline-block;width:150px}.wafs_conditions_meta_box>p:first-child+div>.or_match{display:none}.condition-group{margin-bottom:30px;background-color:#f5f5f5;padding:15px 20px 20px;border:1px solid #ddd;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04)}.wafs-condition-wrap{margin:10px 0px 5px}.wafs-condition-wrap .wafs-condition{width:30%}.wafs-condition-wrap .wafs-operator{width:12%;min-width:140px}.wafs-condition-wrap .wafs-value{width:30%}.wafs-condition-wrap input{vertical-align:top}#wafs_conditions p+p{display:none}.wafs_desc{display:none;position:absolute;background:rgba(0,0,0,0.8);min-width:25px;max-width:200px;border-radius:6px;padding:5px 10px;color:white;margin-top:10px;right:40px;text-align:center}.wafs_desc:after{border-top:0px solid transparent;border-right:10px solid transparent;border-left:10px solid transparent;border-bottom:10px solid rgba(0,0,0,0.8);content:' ';position:absolute;top:-10px;right:10px;z-index:999}.wafs_tip:hover ~ .wafs_desc{display:block !important}.wafs-description{width:40px;float:right;line-height:20px}.wafs-condition-wrap ~ .loading-icon{display:block}.loading-icon{width:30%;clear:both;display:inline-block;text-align:center;line-height:110%;margin:0 1px}.condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wafs-condition-wrap:hover .condition-delete{display:inline-block;opacity:1}.add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}#advanced_free_shipping_shipping_methods tr .row-actions{visibility:hidden}#advanced_free_shipping_shipping_methods tr:hover>td>.row-actions{visibility:visible !important} 
     1.wpc-conditions .wpc-condition-group{background-color:#f5f5f5;padding:15px;border:1px solid #e5e5e5;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.04);box-shadow:0 1px 1px rgba(0,0,0,0.04);min-height:30px;margin:0 -13px 1.5em}.wpc-conditions .wpc-condition-group:hover .wpc-condition-group-actions{opacity:1}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions{opacity:0;margin:-10px -10px 0 0;font-size:80%}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a{text-decoration:none}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete{color:#a00}.wpc-conditions .wpc-condition-group .wpc-condition-group-actions a.delete:hover{color:#f00}.wpc-conditions .wpc-condition-group .wpc-condition-wrap{margin:10px 0 5px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-condition{width:35%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-operator{width:22.5%}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-value{width:calc( 42.5% - 75px );height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description{float:right}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip{height:28px;line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap .wpc-description .woocommerce-help-tip:after{line-height:28px}.wpc-conditions .wpc-condition-group .wpc-condition-wrap input{vertical-align:top}.wpc-conditions .clearfix:after{content:" ";display:block;height:0;clear:both}.wpc-conditions .wpc-add.button:before{font-family:'dashicons';content:"\f502";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;margin-right:5px;color:#667}.wpc-conditions .wpc-condition-delete.button{font-weight:600;width:30px;text-align:center;padding:0}.wpc-conditions .wpc-condition-delete.button:before{font-family:'dashicons';content:"\f460";vertical-align:middle;height:1.2em;line-height:1;display:inline-block;color:#667}.wpc-conditions>p+.wpc-condition-group-wrap p.or-text{display:none}.wpc-conditions .or-text{margin:1.5em 0}.wpc-conditions .match-text{margin:0 0 1em}.wpc-conditions .wpc-condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wpc-conditions .wpc-condition-wrap:hover .wpc-condition-delete{display:inline-block;opacity:1}.wpc-conditions .wpc-condition-wrap.loading{height:30px}.wpc-conditions .wpc-condition-wrap.loading .loading-icon{width:100%;clear:both;display:block;text-align:center;line-height:110%;margin:0 1px}.wpc-condition-wrap .wpc-value.select2-container{display:inline-block !important;margin:1px}.wpc-condition-wrap .wpc-value.select2-container.select2-container-active .select2-choice{border:1px solid #666}.wpc-condition-wrap .wpc-value.select2-container.select2-drop-above .select2-choice{border-radius:0 0 4px 4px;border:1px solid #666;border-top-color:transparent}.wpc-condition-wrap .wpc-value.select2-container .select2-choice{border-color:#ddd;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;height:26px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.07);box-shadow:inset 0 1px 2px rgba(0,0,0,0.07)}.wpc-condition-wrap .wpc-value.select2-dropdown-open .select2-choice{border-bottom-color:transparent;-webkit-box-shadow:0 1px 0 #fff inset;box-shadow:0 1px 0 #fff inset;border-bottom-left-radius:0;border-bottom-right-radius:0;border:1px solid #666;outline:0}.wpc-condition-wrap .select2-container .select2-selection--single{height:28px !important}.wpc-condition-wrap .select2-container .select2-selection--single #select2--container,.wpc-condition-wrap .select2-container .select2-selection--single .select2-selection__arrow{line-height:26px}.wpc-condition-wrap .select2-container .select2-selection--single .select2-selection__arrow{height:28px}.wpc-conditions-post-table .sort{padding:0 4px;cursor:move;text-align:center;vertical-align:middle}.wpc-conditions-post-table .sort:before{content:"\e032";font-family:WooCommerce;text-align:center;line-height:1;color:#999;display:block;width:100%;float:left;height:100%}.wpc-conditions-post-table .sort:before,.wpc-conditions-post-table .row-actions{visibility:hidden !important}.wpc-conditions-post-table tr:hover .sort:before,.wpc-conditions-post-table tr:hover>td>.row-actions{visibility:visible !important}.wpc-conditions-post-table .add.button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;margin-right:7px;content:"\e007"}@media screen and (max-width: 782px){.wpc-conditions-post-table th{padding:8px}.wpc-conditions-post-table td{padding:8px 10px}.wpc-conditions-post-table tfoot .button{margin-bottom:0}}.wpc-currency{padding:3px 10px;font-size:14px;font-weight:400;line-height:19px;height:27px;box-sizing:border-box;color:#555;text-align:center;background-color:#EEE;border:1px solid #DDD;border-right:none;border-radius:4px 0px 0px 4px;margin:1px 0px 1px 1px;display:inline-block}.wpc-currency+input{margin-left:-4px;line-height:19px;width:161px !important}@media screen and (max-width: 782px){.wpc-currency{font-size:16px;padding:6px 10px;height:33px}}.post-type-wafs .misc-pub-visibility#visibility{display:none}.wafs-option label{display:inline-block;width:150px}.wafs_conditions_meta_box>p:first-child+div>.or_match{display:none}.wafs_desc{display:none;position:absolute;background:rgba(0,0,0,0.8);min-width:25px;max-width:200px;border-radius:6px;padding:5px 10px;color:white;margin-top:10px;right:40px;text-align:center}.wafs_desc:after{border-top:0px solid transparent;border-right:10px solid transparent;border-left:10px solid transparent;border-bottom:10px solid rgba(0,0,0,0.8);content:' ';position:absolute;top:-10px;right:10px;z-index:999}.wafs_tip:hover ~ .wafs_desc{display:block !important}.wafs-description{width:40px;float:right;line-height:20px}.condition-delete{display:none;opacity:0;transition:opacity .3s ease-in-out}.wafs-condition-wrap:hover .condition-delete{display:inline-block;opacity:1}#advanced_free_shipping_shipping_methods tr .row-actions{visibility:hidden}#advanced_free_shipping_shipping_methods tr:hover>td>.row-actions{visibility:visible !important} 
  • woocommerce-advanced-free-shipping/trunk/assets/css/woocommerce-advanced-free-shipping.scss

    r1483190 r1609491  
    1 @import 'parts/wp-conditions'; 
     1@import '../../libraries/wp-conditions/assets/css/wp-conditions'; 
    22 
    33/* Hide visibility from admin */ 
     
    1414    display: none; 
    1515} 
    16 /* 
    17  * Condition group 
    18  */ 
    19 .condition-group { 
    20     margin-bottom: 30px; 
    21     background-color: #f5f5f5; 
    22     padding: 15px 20px 20px; 
    23     border: 1px solid #ddd; 
    24     -webkit-box-shadow: 0 1px 1px rgba( 0, 0, 0, .04); 
    25     box-shadow: 0 1px 1px rgba( 0, 0, 0, .04); 
    26 } 
    27 .wafs-condition-wrap { 
    28     margin: 10px 0px 5px; 
    29 } 
    30 .wafs-condition-wrap .wafs-condition { 
    31     width: 30%; 
    32 } 
    33 .wafs-condition-wrap .wafs-operator { 
    34     width: 12%; 
    35     min-width: 140px; 
    36 } 
    37 .wafs-condition-wrap .wafs-value { 
    38     width: 30%; 
    39 } 
    40 .wafs-condition-wrap input { 
    41     vertical-align: top; 
    42 } 
    4316 
    44 #wafs_conditions p + p { 
    45     display: none; 
    46 } 
    4717/* Description */ 
    4818.wafs_desc { 
     
    7949} 
    8050 
    81 /* 
    82  * Loading icon 
    83  */ 
    84  
    85 /* Load icon condition row */ 
    86 .wafs-condition-wrap ~ .loading-icon { 
    87     display: block; 
    88 } 
    89 .loading-icon { 
    90     width: 30%; 
    91     clear: both; 
    92     display: inline-block; 
    93     text-align: center; 
    94     line-height: 110%; 
    95     margin: 0 1px; 
    96 } 
    97  
    9851.condition-delete { 
    9952    display: none; 
     
    10659} 
    10760 
    108  
    109 /* WooCommerce Add icon */ 
    110 .add.button:before { 
    111     font-family: WooCommerce; 
    112     speak: none; 
    113     font-weight: 400; 
    114     font-variant: normal; 
    115     text-transform: none; 
    116     line-height: 1; 
    117     -webkit-font-smoothing: antialiased; 
    118     margin-right: 7px; 
    119     content: "\e007"; 
    120 } 
    12161/* Overview row actions */ 
    12262#advanced_free_shipping_shipping_methods tr .row-actions { 
  • woocommerce-advanced-free-shipping/trunk/codeoversight.yml

    r1483190 r1609491  
    11php: 
    22    align_array_elements: space 
    3     align_doc_tags: double_space 
     3    align_doc_tags: space 
    44    align_variables: space 
    55    closing_newline: add 
     
    2727    use_quotes: single_quotes 
    2828    variable_array_index_whitespace: whitespace 
    29     whitespace_after_control_structure: whitespace 
    3029    whitespace_after_doc_asterisk: single_space 
    3130    whitespace_after_else: space 
     
    3332    whitespace_after_function: double_newline 
    3433    whitespace_before_control_structure_brace: space 
     34    whitespace_before_control_structure_parentheses: whitespace 
    3535    whitespace_before_doc_asterisk: space 
    3636    whitespace_before_else: space 
     
    3838    whitespace_before_function_close: newline 
    3939    whitespace_before_function_parentheses: no_space 
     40 
     41blacklist: 
     42  directories: 
     43    - libraries 
  • woocommerce-advanced-free-shipping/trunk/includes/admin/class-wafs-admin.php

    r1483190 r1609491  
    1919     * @since 1.0.8 
    2020     */ 
    21     public function __construct() { 
    22  
    23         // Initialize plugin parts 
    24         add_action( 'admin_init', array( $this, 'init' ) ); 
    25  
    26     } 
     21    public function __construct() {} 
    2722 
    2823 
     
    4540        global $pagenow; 
    4641        if ( 'plugins.php' == $pagenow ) : 
    47             // Plugins page 
    4842            add_filter( 'plugin_action_links_' . plugin_basename( WAFS()->file ), array( $this, 'add_plugin_action_links' ), 10, 2 ); 
    4943        endif; 
     
    6559        wp_register_style( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/css/woocommerce-advanced-free-shipping.min.css', WAFS()->file ), array(), WAFS()->version ); 
    6660        wp_register_script( 'woocommerce-advanced-free-shipping', plugins_url( 'assets/js/woocommerce-advanced-free-shipping' . $suffix . '.js', WAFS()->file ), array( 'jquery' ), WAFS()->version, true ); 
    67         wp_localize_script( 'woocommerce-advanced-free-shipping', 'wpc', array( 
    68             'nonce'         => wp_create_nonce( 'wpc-ajax-nonce' ), 
    69             'action_prefix' => 'wafs_', 
    70             'asset_url'     => plugins_url( 'assets/', WAFS()->file ), 
     61        wp_localize_script( 'woocommerce-advanced-free-shipping', 'wafs', array( 
     62            'nonce' => wp_create_nonce( 'wpc-ajax-nonce' ), 
    7163        ) ); 
    7264 
     
    7769        ) : 
    7870 
     71            wp_localize_script( 'wp-conditions', 'wpc2', array( 
     72                'action_prefix' => 'wafs_', 
     73            ) ); 
     74 
    7975            wp_enqueue_style( 'woocommerce-advanced-free-shipping' ); 
    8076            wp_enqueue_script( 'woocommerce-advanced-free-shipping' ); 
     77            wp_enqueue_script( 'wp-conditions' ); 
     78 
    8179            wp_dequeue_script( 'autosave' ); 
    8280 
  • woocommerce-advanced-free-shipping/trunk/includes/admin/class-wafs-condition.php

    r1490367 r1609491  
    5959     * @since 1.0.0 
    6060     */ 
    61     public function __construct( $id = null, $group = 0, $condition = null, $operator = null, $value = null ) { 
     61    public function __construct( $id = null, $group = 0, $condition = 'subtotal', $operator = null, $value = null ) { 
    6262 
    6363        $this->id        = $id; 
     
    145145     */ 
    146146    public function get_operators() { 
    147  
    148         $operators = array( 
    149             '==' => __( 'Equal to', 'woocommerce-advanced-free-shipping' ), 
    150             '!=' => __( 'Not equal to', 'woocommerce-advanced-free-shipping' ), 
    151             '>=' => __( 'Greater or equal to', 'woocommerce-advanced-free-shipping' ), 
    152             '<=' => __( 'Less or equal to ', 'woocommerce-advanced-free-shipping' ), 
    153         ); 
    154         $operators = apply_filters( 'wafs_operators', $operators ); 
    155  
    156         return $operators; 
    157  
     147        $wpc_condition = wpc_get_condition( $this->condition ); 
     148        return apply_filters( 'woocommerce_Advanced_Shipping_Validation_operators', $wpc_condition->get_available_operators() ); 
    158149    } 
    159150 
     
    172163 
    173164        // Defaults 
    174         $values = array( 
     165        $default_field_args = array( 
    175166            'name'        => 'conditions[' . absint( $this->group ) . '][' . absint( $this->id ) . '][value]', 
    176167            'placeholder' => '', 
    177168            'type'        => 'text', 
    178             'class'       => array( 'wpc-value' ) 
     169            'class'       => array( 'wpc-value' ), 
    179170        ); 
    180171 
    181  
    182  
    183         switch ( $this->condition ) : 
    184  
    185             default: 
    186             case 'subtotal' : 
    187             case 'subtotal_ex_tax' : 
    188             case 'tax' : 
    189             case 'quantity' : 
    190             case 'coupon' : 
    191             case 'weight' : 
    192                 $values['type'] = 'text'; 
    193             break; 
    194  
    195             case 'contains_product' : 
    196  
    197                 $product = wc_get_product( $this->value ); 
    198                 if ( $product ) { 
    199                     $values['custom_attributes']['data-selected'] = $product->get_formatted_name(); 
    200                 } 
    201  
    202                 $values['type']        = 'text'; 
    203                 $values['placeholder'] =  __( 'Search for a product', 'woocommerce-advanced-messages' ); 
    204                 $values['class'][]     = 'wc-product-search'; 
    205  
    206             break; 
    207  
    208             case 'contains_shipping_class' : 
    209  
    210                 $values['type']        = 'select'; 
    211                 $values['options'][''] = __( 'No shipping class', 'woocommerce' ); 
    212  
    213                 // Get all shipping classes 
    214                 foreach ( get_terms( 'product_shipping_class', array( 'hide_empty' => false ) ) as $shipping_class ) : 
    215                     $values['options'][ $shipping_class->slug ] = $shipping_class->name; 
    216                 endforeach; 
    217  
    218             break; 
    219  
    220             /** 
    221              * User details 
    222              */ 
    223  
    224             case 'zipcode' : 
    225             case 'city' : 
    226                 $values['type'] = 'text'; 
    227             break; 
    228  
    229             case 'state' : 
    230  
    231                 $values['type']    = 'select'; 
    232                 $values['class'][] = 'wc-enhanced-select'; 
    233  
    234                 $country_states = array(); 
    235                 foreach ( WC()->countries->states as $country => $states ) : 
    236  
    237                     if ( empty( $states ) ) continue; // Don't show country if it has no states 
    238                     if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries 
    239  
    240                     foreach ( $states as $state_key => $state ) : 
    241                         $country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state; 
    242                     endforeach; 
    243  
    244                     $values['options'] = $country_states; 
    245  
    246                 endforeach; 
    247  
    248             break; 
    249  
    250             case 'country' : 
    251  
    252                 $values['field']   = 'select'; 
    253                 $values['class'][] = 'wc-enhanced-select'; 
    254  
    255                 $countries  =  WC()->countries->get_allowed_countries() + WC()->countries->get_shipping_countries(); 
    256                 $continents = array(); 
    257                 if ( method_exists( WC()->countries, 'get_continents' ) ) : 
    258                     foreach ( WC()->countries->get_continents() as $k => $v ) : 
    259                         $continents[ 'CO_' . $k ] = $v['name']; // Add prefix for country key compatibility 
    260                     endforeach; 
    261                 endif; 
    262  
    263                 if ( $continents ) { 
    264                     $values['options'][ __( 'Continents', 'woocommerce' ) ] = $continents; 
    265                 } 
    266                 $values['options'][ __( 'Countries', 'woocommerce' ) ] = $countries; 
    267  
    268                 break; 
    269  
    270             case 'role' : 
    271                 $values['type']    = 'select'; 
    272                 $roles             = array_keys( get_editable_roles() ); 
    273                 $values['options'] = array_combine( $roles, $roles ); 
    274             break; 
    275  
    276             /** 
    277              * Product 
    278              */ 
    279  
    280             case 'width' : 
    281             case 'height' : 
    282             case 'length' : 
    283             case 'stock' : 
    284                 $values['type'] = 'text'; 
    285             break; 
    286  
    287             case 'stock_status' : 
    288  
    289                 $values['type']    = 'select'; 
    290                 $values['options'] = array( 
    291                     'instock'    => __( 'In stock', 'woocommerce-advanced-free-shipping' ), 
    292                     'outofstock' => __( 'Out of stock', 'woocommerce-advanced-free-shipping' ), 
    293                 ); 
    294  
    295             break; 
    296  
    297             case 'category' : 
    298  
    299                 $values['type']    = 'select'; 
    300                 $values['class'][] = 'wc-enhanced-select'; 
    301  
    302                 $categories = get_terms( 'product_cat', array( 'hide_empty' => false ) ); 
    303                 foreach ( $categories as $category ) : 
    304                     $values['options'][ $category->slug ] = $category->name; 
    305                 endforeach; 
    306  
    307             break; 
    308  
    309  
    310         endswitch; 
    311  
    312         $values = apply_filters( 'wafs_values', $values, $this->condition ); 
    313  
    314  
    315         $values = apply_filters( 'woocommerce_advanced_free_shipping_values', $values, $this->condition ); 
    316  
    317         return $values; 
     172        $field_args = $default_field_args; 
     173        if ( $condition = wpc_get_condition( $this->condition ) ) { 
     174            $field_args = wp_parse_args( $condition->get_value_field_args(), $field_args ); 
     175        } 
     176 
     177        if ( $this->condition == 'contains_product' && $product = wc_get_product( $this->value ) ) { 
     178            $field_args['custom_attributes']['data-selected'] = $product->get_formatted_name(); // WC < 2.7 
     179            $field_args['options'][ $this->value ] = $product->get_formatted_name(); // WC >= 2.7 
     180        } 
     181 
     182        $field_args = apply_filters( 'wafs_values', $field_args, $this->condition ); 
     183        $field_args = apply_filters( 'woocommerce_advanced_free_shipping_values', $field_args, $this->condition ); 
     184 
     185        return $field_args; 
    318186 
    319187    } 
     
    328196     */ 
    329197    public function get_description() { 
    330  
    331         $descriptions = array( 
    332             'state'                   => __( 'States must be installed in WC.', 'woocommerce-advanced-free-shipping' ), 
    333             'weight'                  => __( 'Weight calculated on all the cart contents', 'woocommerce-advanced-free-shipping' ), 
    334             'length'                  => __( 'Compared to lengthiest product in cart', 'woocommerce-advanced-free-shipping' ), 
    335             'width'                   => __( 'Compared to widest product in cart', 'woocommerce-advanced-free-shipping' ), 
    336             'height'                  => __( 'Compared to highest product in cart', 'woocommerce-advanced-free-shipping' ), 
    337             'stock_status'            => __( 'All products in cart must match stock status', 'woocommerce-advanced-free-shipping' ), 
    338             'category'                => __( 'All products in cart must match category', 'woocommerce-advanced-free-shipping' ), 
    339             'contains_product'        => __( 'Cart must contain one of this product', 'woocommerce-advanced-free-shipping' ), 
    340             'contains_shipping_class' => __( 'Cart must contain at least one product with the selected shipping class', 'woocommerce-advanced-free-shipping' ), 
    341         ); 
    342  
    343         $descriptions = apply_filters( 'wafs_descriptions', $descriptions ); 
    344  
     198        $descriptions = apply_filters( 'wafs_descriptions', wpc_condition_descriptions() ); 
    345199        return isset( $descriptions[ $this->condition ] ) ? $descriptions[ $this->condition ] : ''; 
    346  
    347200    } 
    348201 
  • woocommerce-advanced-free-shipping/trunk/includes/admin/views/conditions-table.php

    r1483190 r1609491  
    2020    <td class="forminp" id="<?php echo $this->id; ?>_shipping_methods"> 
    2121 
    22         <table class='wp-list-table wpc-conditions-post-table widefat'> 
     22        <table class='wp-list-table wpc-conditions-post-table wpc-sortable-post-table widefat'> 
    2323            <thead> 
    2424                <tr> 
  • woocommerce-advanced-free-shipping/trunk/includes/admin/views/html-condition-row.php

    r1483190 r1609491  
    11<?php 
    22if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 
     3 
     4$condition = wpc_get_condition( $wp_condition->condition ); 
    35 
    46?><div class='wpc-condition-wrap'> 
    57 
    68    <!-- Condition --> 
    7     <span class='wpc-condition-wrap wpc-condition-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
     9    <span class='wpc-condition-field-wrap'><?php 
    810 
    911        $condition_field_args = array( 
     
    1416            'value'       => $wp_condition->condition, 
    1517            'custom_attr' => array( 
    16                 'data-group' => absint( $wp_condition->group ), 
    17                 'data-id'    => absint( $wp_condition->id ), 
     18                'data-id' => absint( $wp_condition->id ), 
    1819            ), 
    1920        ); 
     
    2425 
    2526    <!-- Operator --> 
    26     <span class='wpc-operator-wrap wpc-operator-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
     27    <span class='wpc-operator-field-wrap'><?php 
    2728 
    2829        $operator_field_args = array( 
     
    3940 
    4041    <!-- Value --> 
    41     <span class='wpc-value-wrap wpc-value-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
     42    <span class='wpc-value-field-wrap'><?php 
    4243        $value_field_args = wp_parse_args( array( 'value' => $wp_condition->value ), $wp_condition->get_value_field_args() ); 
    4344        wpc_html_field( $value_field_args ); 
     
    4546 
    4647 
    47     <!-- Add / Delete--> 
    48     <a class='button wpc-condition-add' data-group='<?php echo absint( $this->group ); ?>' href='javascript:void(0);'>+</a>&nbsp; 
    49     <a class='button wpc-condition-delete' href='javascript:void(0);'>-</a><?php 
     48    <!-- Delete--> 
     49    <a class='button wpc-condition-delete' href='javascript:void(0);'></a><?php 
    5050 
    5151 
    5252    // Description 
    5353    if ( $desc = $wp_condition->get_description() ) : 
    54         ?><span class='wpc-description <?php echo $wp_condition->condition; ?>-description'> 
    55             <img class='help_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' data-tip="<?php echo esc_html( $desc ); ?>" /> 
     54        ?><span class='wpc-description'> 
     55            <span class="woocommerce-help-tip" data-tip="<?php echo wp_kses_post( $desc ); ?>"></span> 
    5656        </span><?php 
    5757    else : 
    58         ?><span class='wpc-description wpc-no-description <?php echo $wp_condition->condition; ?>-description'><?php 
     58        ?><span class='wpc-description wpc-no-description'><?php 
    5959    endif; 
    6060 
  • woocommerce-advanced-free-shipping/trunk/includes/admin/views/meta-box-conditions.php

    r1483190 r1609491  
    88 
    99    <p> 
    10         <strong><?php _e( 'Match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong> 
     10        <strong><?php _e( 'Match one of the condition groups to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></strong> 
    1111    </p><?php 
    1212 
     
    1414 
    1515        foreach ( $condition_groups as $condition_group => $conditions ) : 
    16  
    17             ?><div class='wpc-condition-group wpc-condition-group-<?php echo absint( $condition_group ); ?>' data-group='<?php echo absint( $condition_group ); ?>'> 
    18  
    19                 <p class='or-text'><?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></p><?php 
    20  
    21                 foreach ( $conditions as $condition_id => $condition ) : 
    22                     $wp_condition = new WAFS_Condition( $condition_id, $condition_group, $condition['condition'], $condition['operator'], $condition['value'] ); 
    23                     $wp_condition->output_condition_row(); 
    24                 endforeach; 
    25  
    26             ?></div> 
    27  
    28             <p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php 
    29  
     16            include plugin_dir_path( __FILE__ ) . 'html-condition-group.php'; 
    3017        endforeach; 
    3118 
    3219    else : 
    3320 
    34         ?><div class='wpc-condition-group wpc-condition-group-0' data-group='0'><?php 
    35             $wp_condition = new WAFS_Condition(); 
    36             $wp_condition->output_condition_row(); 
    37         ?></div><?php 
     21        $condition_group = '0'; 
     22        include plugin_dir_path( __FILE__ ) . 'html-condition-group.php'; 
    3823 
    3924    endif; 
    4025 
    41     ?></div> 
     26?></div> 
    4227 
     28<div class='wpc-condition-group-template hidden' style='display: none'><?php 
     29    $condition_group = '9999'; 
     30    $conditions      = array(); 
     31    include plugin_dir_path( __FILE__ ) . 'html-condition-group.php'; 
     32?></div> 
    4333<a class='button wpc-condition-group-add' href='javascript:void(0);'><?php _e( 'Add \'Or\' group', 'woocommerce-advanced-free-shipping' ); ?></a> 
  • woocommerce-advanced-free-shipping/trunk/includes/admin/views/meta-box-settings.php

    r1483190 r1609491  
    3333    </p> 
    3434 
    35  
    3635</div> 
  • woocommerce-advanced-free-shipping/trunk/includes/class-wafs-ajax.php

    r1483190 r1609491  
    2020    public function __construct() { 
    2121 
    22         // Add elements 
    23         add_action( 'wp_ajax_wafs_add_condition', array( $this, 'add_condition' ) ); 
    24         add_action( 'wp_ajax_wafs_add_condition_group', array( $this, 'add_condition_group' ) ); 
    25  
    2622        // Update elements 
    2723        add_action( 'wp_ajax_wafs_update_condition_value', array( $this, 'update_condition_value' ) ); 
    28         add_action( 'wp_ajax_wafs_update_condition_description', array( $this, 'update_condition_description' ) ); 
    29  
    30     } 
    31  
    32  
    33     /** 
    34      * Add condition. 
    35      * 
    36      * Output the HTML of a new condition row. 
    37      * 
    38      * @since 1.0.0 
    39      */ 
    40     public function add_condition() { 
    41  
    42         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    43  
    44         $wp_condition = new WAFS_Condition( null, $_POST['group'] ); 
    45         $wp_condition->output_condition_row(); 
    46  
    47         die(); 
    48  
    49     } 
    50  
    51  
    52     /** 
    53      * Condition group. 
    54      * 
    55      * Output the HTML of a new condition group. 
    56      * 
    57      * @since 1.0.0 
    58      */ 
    59     public function add_condition_group() { 
    60  
    61         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    62         $group = absint( $_POST['group'] ); 
    63  
    64         ?><div class='wpc-condition-group wpc-condition-group-<?php echo $group; ?>' data-group='<?php echo $group; ?>'> 
    65  
    66             <p class='or-match'><?php _e( 'Or match all of the following rules to allow free shipping:', 'woocommerce-advanced-free-shipping' ); ?></p><?php 
    67  
    68             $wp_condition = new WAFS_Condition( null, $group ); 
    69             $wp_condition->output_condition_row(); 
    70  
    71         ?></div> 
    72  
    73         <p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-free-shipping' ); ?></strong></p><?php 
    74  
    75         die(); 
    7624 
    7725    } 
     
    9240        $value_field_args = $wp_condition->get_value_field_args(); 
    9341 
    94         ?><span class='wpc-value-wrap wpc-value-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
     42        ?><span class='wpc-value-field-wrap'><?php 
    9543            wpc_html_field( $value_field_args ); 
    9644        ?></span><?php 
     
    10149 
    10250 
    103     /** 
    104      * Update description. 
    105      * 
    106      * Render the corresponding description for the condition key. 
    107      * 
    108      * @since 1.0.0 
    109      */ 
    110     public function update_condition_description() { 
    111  
    112         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    113  
    114         $condition    = sanitize_text_field( $_POST['condition'] ); 
    115         $wp_condition = new WAFS_Condition( null, null, $condition ); 
    116  
    117         if ( $desc = $wp_condition->get_description() ) { 
    118             ?><span class='wpc-description wpc-no-description <?php echo $desc; ?>-description'><?php 
    119             die(); 
    120         } 
    121  
    122         ?><span class='wpc-description <?php echo $wp_condition->condition; ?>-description'> 
    123             <img class='help_tip' src='<?php echo WC()->plugin_url(); ?>/assets/images/help.png' height='24' width='24' data-tip="<?php echo esc_html( $wp_condition->get_description() ); ?>" /> 
    124         </span><?php 
    125  
    126         die(); 
    127  
    128     } 
    129  
    130  
    13151} 
  • woocommerce-advanced-free-shipping/trunk/includes/class-wafs-match-conditions.php

    r1490367 r1609491  
    2020     */ 
    2121    public function __construct() { 
    22  
    23         add_filter( 'wafs_match_condition_subtotal', array( $this, 'wafs_match_condition_subtotal' ), 10, 3 ); 
    24         add_filter( 'wafs_match_condition_subtotal_ex_tax', array( $this, 'wafs_match_condition_subtotal_ex_tax' ), 10, 3 ); 
    25         add_filter( 'wafs_match_condition_tax', array( $this, 'wafs_match_condition_tax' ), 10, 3 ); 
    26         add_filter( 'wafs_match_condition_quantity', array( $this, 'wafs_match_condition_quantity' ), 10, 3 ); 
    27         add_filter( 'wafs_match_condition_contains_product', array( $this, 'wafs_match_condition_contains_product' ), 10, 3 ); 
    28         add_filter( 'wafs_match_condition_coupon', array( $this, 'wafs_match_condition_coupon' ), 10, 3 ); 
    29         add_filter( 'wafs_match_condition_weight', array( $this, 'wafs_match_condition_weight' ), 10, 3 ); 
    30         add_filter( 'wafs_match_condition_contains_shipping_class', array( $this, 'wafs_match_condition_contains_shipping_class' ), 10, 3 ); 
    31  
    3222        add_filter( 'wafs_match_condition_zipcode', array( $this, 'wafs_match_condition_zipcode' ), 10, 3 ); 
    33         add_filter( 'wafs_match_condition_city', array( $this, 'wafs_match_condition_city' ), 10, 3 ); 
    34         add_filter( 'wafs_match_condition_state', array( $this, 'wafs_match_condition_state' ), 10, 3 ); 
    35         add_filter( 'wafs_match_condition_country', array( $this, 'wafs_match_condition_country' ), 10, 3 ); 
    36         add_filter( 'wafs_match_condition_role', array( $this, 'wafs_match_condition_role' ), 10, 3 ); 
    37  
    38         add_filter( 'wafs_match_condition_width', array( $this, 'wafs_match_condition_width' ), 10, 3 ); 
    39         add_filter( 'wafs_match_condition_height', array( $this, 'wafs_match_condition_height' ), 10, 3 ); 
    40         add_filter( 'wafs_match_condition_length', array( $this, 'wafs_match_condition_length' ), 10, 3 ); 
    41         add_filter( 'wafs_match_condition_stock', array( $this, 'wafs_match_condition_stock' ), 10, 3 ); 
    42         add_filter( 'wafs_match_condition_stock_status', array( $this, 'wafs_match_condition_stock_status' ), 10, 3 ); 
    43         add_filter( 'wafs_match_condition_category', array( $this, 'wafs_match_condition_category' ), 10, 3 ); 
    44  
    4523    } 
    46  
    47  
    48     /** 
    49      * Subtotal. 
    50      * 
    51      * Match the condition value against the cart subtotal. 
    52      * 
    53      * @since 1.0.0 
    54      * 
    55      * @param   bool    $match     Current match value. 
    56      * @param   string  $operator  Operator selected by the user in the condition row. 
    57      * @param   mixed   $value     Value given by the user in the condition row. 
    58      * @return  bool               Matching result, true if results match, otherwise false. 
    59      */ 
    60     public function wafs_match_condition_subtotal( $match, $operator, $value ) { 
    61  
    62         if ( ! isset( WC()->cart ) ) return $match; 
    63  
    64         if ( '==' == $operator ) : 
    65             $match = ( WC()->cart->subtotal == $value ); 
    66         elseif ( '!=' == $operator ) : 
    67             $match = ( WC()->cart->subtotal != $value ); 
    68         elseif ( '>=' == $operator ) : 
    69             $match = ( WC()->cart->subtotal >= $value ); 
    70         elseif ( '<=' == $operator ) : 
    71             $match = ( WC()->cart->subtotal <= $value ); 
    72         endif; 
    73  
    74         return $match; 
    75  
    76     } 
    77  
    78  
    79     /** 
    80      * Subtotal excl. taxes. 
    81      * 
    82      * Match the condition value against the cart subtotal excl. taxes. 
    83      * 
    84      * @since 1.0.0 
    85      * 
    86      * @param   bool    $match     Current match value. 
    87      * @param   string  $operator  Operator selected by the user in the condition row. 
    88      * @param   mixed   $value     Value given by the user in the condition row. 
    89      * @return  bool               Matching result, true if results match, otherwise false. 
    90      */ 
    91     public function wafs_match_condition_subtotal_ex_tax( $match, $operator, $value ) { 
    92  
    93         if ( ! isset( WC()->cart ) ) return $match; 
    94  
    95         if ( '==' == $operator ) : 
    96             $match = ( WC()->cart->subtotal_ex_tax == $value ); 
    97         elseif ( '!=' == $operator ) : 
    98             $match = ( WC()->cart->subtotal_ex_tax != $value ); 
    99         elseif ( '>=' == $operator ) : 
    100             $match = ( WC()->cart->subtotal_ex_tax >= $value ); 
    101         elseif ( '<=' == $operator ) : 
    102             $match = ( WC()->cart->subtotal_ex_tax <= $value ); 
    103         endif; 
    104  
    105         return $match; 
    106  
    107     } 
    108  
    109  
    110     /** 
    111      * Taxes. 
    112      * 
    113      * Match the condition value against the cart taxes. 
    114      * 
    115      * @since 1.0.0 
    116      * 
    117      * @param   bool    $match     Current match value. 
    118      * @param   string  $operator  Operator selected by the user in the condition row. 
    119      * @param   mixed   $value     Value given by the user in the condition row. 
    120      * @return  bool               Matching result, true if results match, otherwise false. 
    121      */ 
    122     public function wafs_match_condition_tax( $match, $operator, $value ) { 
    123  
    124         if ( ! isset( WC()->cart ) ) return $match; 
    125  
    126         $taxes = array_sum( (array) WC()->cart->taxes ); 
    127  
    128         if ( '==' == $operator ) : 
    129             $match = ( $taxes == $value ); 
    130         elseif ( '!=' == $operator ) : 
    131             $match = ( $taxes != $value ); 
    132         elseif ( '>=' == $operator ) : 
    133             $match = ( $taxes >= $value ); 
    134         elseif ( '<=' == $operator ) : 
    135             $match = ( $taxes <= $value ); 
    136         endif; 
    137  
    138         return $match; 
    139  
    140     } 
    141  
    142  
    143     /** 
    144      * Quantity. 
    145      * 
    146      * Match the condition value against the cart quantity. 
    147      * This also includes product quantities. 
    148      * 
    149      * @since 1.0.0 
    150      * 
    151      * @param   bool    $match     Current match value. 
    152      * @param   string  $operator  Operator selected by the user in the condition row. 
    153      * @param   mixed   $value     Value given by the user in the condition row. 
    154      * @return  bool               Matching result, true if results match, otherwise false. 
    155      */ 
    156     public function wafs_match_condition_quantity( $match, $operator, $value ) { 
    157  
    158         if ( ! isset( WC()->cart ) ) return $match; 
    159  
    160         if ( '==' == $operator ) : 
    161             $match = ( WC()->cart->cart_contents_count == $value ); 
    162         elseif ( '!=' == $operator ) : 
    163             $match = ( WC()->cart->cart_contents_count != $value ); 
    164         elseif ( '>=' == $operator ) : 
    165             $match = ( WC()->cart->cart_contents_count >= $value ); 
    166         elseif ( '<=' == $operator ) : 
    167             $match = ( WC()->cart->cart_contents_count <= $value ); 
    168         endif; 
    169  
    170         return $match; 
    171  
    172     } 
    173  
    174  
    175     /** 
    176      * Contains product. 
    177      * 
    178      * Matches if the condition value product is in the cart. 
    179      * 
    180      * @since 1.0.0 
    181      * 
    182      * @param   bool    $match     Current match value. 
    183      * @param   string  $operator  Operator selected by the user in the condition row. 
    184      * @param   mixed   $value     Value given by the user in the condition row. 
    185      * @return  bool               Matching result, true if results match, otherwise false. 
    186      */ 
    187     public function wafs_match_condition_contains_product( $match, $operator, $value ) { 
    188  
    189         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    190  
    191         $product_ids = array(); 
    192         foreach ( WC()->cart->cart_contents as $product ) : 
    193             $product_ids[] = $product['product_id']; 
    194         endforeach; 
    195  
    196         if ( '==' == $operator ) : 
    197             $match = ( in_array( $value, $product_ids ) ); 
    198         elseif ( '!=' == $operator ) : 
    199             $match = ( ! in_array( $value, $product_ids ) ); 
    200         endif; 
    201  
    202         return $match; 
    203  
    204     } 
    205  
    206  
    207     /** 
    208      * Coupon. 
    209      * 
    210      * Match the condition value against the applied coupons. 
    211      * 
    212      * @since 1.0.0 
    213      * 
    214      * @param   bool    $match     Current match value. 
    215      * @param   string  $operator  Operator selected by the user in the condition row. 
    216      * @param   mixed   $value     Value given by the user in the condition row. 
    217      * @return  bool               Matching result, true if results match, otherwise false. 
    218      */ 
    219     public function wafs_match_condition_coupon( $match, $operator, $value ) { 
    220  
    221         if ( ! isset( WC()->cart ) ) : 
    222             return $match; 
    223         endif; 
    224  
    225         $coupons = array( 'percent' => array(), 'fixed' => array() ); 
    226         foreach ( WC()->cart->get_coupons() as $coupon ) { 
    227             $type               = str_replace( '_product', '', $coupon->discount_type ); 
    228             $type               = str_replace( '_cart', '', $type ); 
    229             $coupons[ $type ][] = $coupon->coupon_amount; 
    230         } 
    231  
    232         // Match against coupon percentage 
    233         if ( strpos( $value, '%' ) !== false ) { 
    234  
    235             $percentage_value = str_replace( '%', '', $value ); 
    236             if ( '==' == $operator ) : 
    237                 $match = in_array( $percentage_value, $coupons['percent'] ); 
    238             elseif ( '!=' == $operator ) : 
    239                 $match = ! in_array( $percentage_value, $coupons['percent'] ); 
    240             elseif ( '>=' == $operator ) : 
    241                 $match = empty( $coupons['percent'] ) ? $match : ( min( $coupons['percent'] ) >= $percentage_value ); 
    242             elseif ( '<=' == $operator ) : 
    243                 $match = ! is_array( $coupons['percent'] ) ? false : ( max( $coupons['percent'] ) <= $percentage_value ); 
    244             endif; 
    245  
    246             // Match against coupon amount 
    247         } elseif( strpos( $value, '$' ) !== false ) { 
    248  
    249             $amount_value = str_replace( '$', '', $value ); 
    250             if ( '==' == $operator ) : 
    251                 $match = in_array( $amount_value, $coupons['fixed'] ); 
    252             elseif ( '!=' == $operator ) : 
    253                 $match = ! in_array( $amount_value, $coupons['fixed'] ); 
    254             elseif ( '>=' == $operator ) : 
    255                 $match = empty( $coupons['fixed'] ) ? $match : ( min( $coupons['fixed'] ) >= $amount_value ); 
    256             elseif ( '<=' == $operator ) : 
    257                 $match = ! is_array( $coupons['fixed'] ) ? $match : ( max( $coupons['fixed'] ) <= $amount_value ); 
    258             endif; 
    259  
    260             // Match coupon codes 
    261         } else { 
    262  
    263             if ( '==' == $operator ) : 
    264                 $match = ( in_array( $value, WC()->cart->applied_coupons ) ); 
    265             elseif ( '!=' == $operator ) : 
    266                 $match = ( ! in_array( $value, WC()->cart->applied_coupons ) ); 
    267             endif; 
    268  
    269         } 
    270  
    271         return $match; 
    272  
    273     } 
    274  
    275  
    276     /** 
    277      * Weight. 
    278      * 
    279      * Match the condition value against the cart weight. 
    280      * 
    281      * @since 1.0.0 
    282      * 
    283      * @param   bool    $match     Current match value. 
    284      * @param   string  $operator  Operator selected by the user in the condition row. 
    285      * @param   mixed   $value     Value given by the user in the condition row. 
    286      * @return  bool               Matching result, true if results match, otherwise false. 
    287      */ 
    288     public function wafs_match_condition_weight( $match, $operator, $value ) { 
    289  
    290         if ( ! isset( WC()->cart ) ) return $match; 
    291  
    292         if ( '==' == $operator ) : 
    293             $match = ( WC()->cart->cart_contents_weight == $value ); 
    294         elseif ( '!=' == $operator ) : 
    295             $match = ( WC()->cart->cart_contents_weight != $value ); 
    296         elseif ( '>=' == $operator ) : 
    297             $match = ( WC()->cart->cart_contents_weight >= $value ); 
    298         elseif ( '<=' == $operator ) : 
    299             $match = ( WC()->cart->cart_contents_weight <= $value ); 
    300         endif; 
    301  
    302         return $match; 
    303  
    304     } 
    305  
    306  
    307     /** 
    308      * Shipping class. 
    309      * 
    310      * Matches if the condition value shipping class is in the cart. 
    311      * 
    312      * @since 1.1.0 
    313      * 
    314      * @param   bool    $match     Current match value. 
    315      * @param   string  $operator  Operator selected by the user in the condition row. 
    316      * @param   mixed   $value     Value given by the user in the condition row. 
    317      * @return  bool               Matching result, true if results match, otherwise false. 
    318      */ 
    319     public function wafs_match_condition_contains_shipping_class( $match, $operator, $value ) { 
    320  
    321         if ( ! isset( WC()->cart ) ) return $match; 
    322  
    323         // True until proven false 
    324         if ( $operator == '!=' ) : 
    325             $match = true; 
    326         endif; 
    327  
    328         foreach ( WC()->cart->cart_contents as $product ) : 
    329  
    330             $id      = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id']; 
    331             $product = wc_get_product( $id ); 
    332  
    333             if ( $operator == '==' ) : 
    334                 if ( $product->get_shipping_class() == $value ) : 
    335                     return true; 
    336                 endif; 
    337             elseif ( $operator == '!=' ) : 
    338                 if ( $product->get_shipping_class() == $value ) : 
    339                     return false; 
    340                 endif; 
    341             endif; 
    342  
    343         endforeach; 
    344  
    345         return $match; 
    346  
    347     } 
    348  
    349  
    350 /****************************************************** 
    351  * User conditions 
    352  *****************************************************/ 
    35324 
    35425 
     
    451122 
    452123 
    453     /** 
    454      * City. 
    455      * 
    456      * Match the condition value against the users shipping city. 
    457      * 
    458      * @since 1.0.0 
    459      * 
    460      * @param   bool    $match     Current match value. 
    461      * @param   string  $operator  Operator selected by the user in the condition row. 
    462      * @param   mixed   $value     Value given by the user in the condition row. 
    463      * @return  bool               Matching result, true if results match, otherwise false. 
    464      */ 
    465     public function wafs_match_condition_city( $match, $operator, $value ) { 
    466  
    467         if ( ! isset( WC()->customer ) ) return $match; 
    468  
    469         $customer_city = strtolower( WC()->customer->get_shipping_city() ); 
    470         $value         = strtolower( $value ); 
    471  
    472         if ( '==' == $operator ) : 
    473  
    474             if ( preg_match( '/\, ?/', $value ) ) : 
    475                 $match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) ); 
    476             else : 
    477                 $match = ( $value == $customer_city ); 
    478             endif; 
    479  
    480         elseif ( '!=' == $operator ) : 
    481  
    482             if ( preg_match( '/\, ?/', $value ) ) : 
    483                 $match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) ); 
    484             else : 
    485                 $match = ( $value == $customer_city ); 
    486             endif; 
    487  
    488         endif; 
    489  
    490         return $match; 
    491  
    492     } 
    493  
    494  
    495     /** 
    496      * State. 
    497      * 
    498      * Match the condition value against the users shipping state 
    499      * 
    500      * @since 1.0.0 
    501      * 
    502      * @param   bool    $match     Current match value. 
    503      * @param   string  $operator  Operator selected by the user in the condition row. 
    504      * @param   mixed   $value     Value given by the user in the condition row. 
    505      * @return  bool               Matching result, true if results match, otherwise false. 
    506      */ 
    507     public function wafs_match_condition_state( $match, $operator, $value ) { 
    508  
    509         if ( ! isset( WC()->customer ) ) return $match; 
    510  
    511         $state = WC()->customer->get_shipping_country() . '_' . WC()->customer->get_shipping_state(); 
    512  
    513         if ( '==' == $operator ) : 
    514             $match = ( $state == $value ); 
    515         elseif ( '!=' == $operator ) : 
    516             $match = ( $state != $value ); 
    517         endif; 
    518  
    519         return $match; 
    520  
    521     } 
    522  
    523  
    524     /** 
    525      * Country. 
    526      * 
    527      * Match the condition value against the users shipping country. 
    528      * 
    529      * @since 1.0.0 
    530      * 
    531      * @param   bool    $match     Current match value. 
    532      * @param   string  $operator  Operator selected by the user in the condition row. 
    533      * @param   mixed   $value     Value given by the user in the condition row. 
    534      * @return  bool               Matching result, true if results match, otherwise false. 
    535      */ 
    536     public function wafs_match_condition_country( $match, $operator, $value ) { 
    537  
    538         if ( ! isset( WC()->customer ) ) : 
    539             return $match; 
    540         endif; 
    541  
    542         $user_country = WC()->customer->get_shipping_country(); 
    543  
    544         if ( method_exists( WC()->countries, 'get_continent_code_for_country' ) ) : 
    545             $user_continent = WC()->countries->get_continent_code_for_country( $user_country ); 
    546         endif; 
    547  
    548         if ( '==' == $operator ) : 
    549             $match = stripos( $user_country, $value ) === 0; 
    550  
    551             // Check for continents if available 
    552             if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) : 
    553                 $match = stripos( $user_continent, str_replace( 'CO_','', $value ) ) === 0; 
    554             endif; 
    555         elseif ( '!=' == $operator ) : 
    556             $match = stripos( $user_country, $value ) === false; 
    557  
    558             // Check for continents if available 
    559             if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) : 
    560                 $match = stripos( $user_continent, str_replace( 'CO_','', $value ) ) === false; 
    561             endif; 
    562         endif; 
    563  
    564         return $match; 
    565  
    566     } 
    567  
    568  
    569     /** 
    570      * User role. 
    571      * 
    572      * Match the condition value against the users role. 
    573      * 
    574      * @since 1.0.0 
    575      * @global object $current_user Current user object for capabilities. 
    576      * 
    577      * @param   bool    $match     Current match value. 
    578      * @param   string  $operator  Operator selected by the user in the condition row. 
    579      * @param   mixed   $value     Value given by the user in the condition row. 
    580      * @return  bool               Matching result, true if results match, otherwise false. 
    581      */ 
    582     public function wafs_match_condition_role( $match, $operator, $value ) { 
    583  
    584         global $current_user; 
    585  
    586         if ( '==' == $operator ) : 
    587             $match = ( array_key_exists( $value, $current_user->caps ) ); 
    588         elseif ( '!=' == $operator ) : 
    589             $match = ( ! array_key_exists( $value, $current_user->caps ) ); 
    590         endif; 
    591  
    592         return $match; 
    593  
    594     } 
    595  
    596  
    597 /****************************************************** 
    598  * Product conditions 
    599  *****************************************************/ 
    600  
    601  
    602     /** 
    603      * Width. 
    604      * 
    605      * Match the condition value against the widest product in the cart. 
    606      * 
    607      * @since 1.0.0 
    608      * 
    609      * @param   bool    $match     Current match value. 
    610      * @param   string  $operator  Operator selected by the user in the condition row. 
    611      * @param   mixed   $value     Value given by the user in the condition row. 
    612      * @return  bool               Matching result, true if results match, otherwise false. 
    613      */ 
    614     public function wafs_match_condition_width( $match, $operator, $value ) { 
    615  
    616         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    617  
    618         foreach ( WC()->cart->cart_contents as $product ) : 
    619  
    620             if ( true == $product['data']->variation_has_width ) : 
    621                 $width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) ); 
    622             else : 
    623                 $width[] = ( get_post_meta( $product['product_id'], '_width', true ) ); 
    624             endif; 
    625  
    626         endforeach; 
    627  
    628         $max_width = max( (array) $width ); 
    629  
    630         if ( '==' == $operator ) : 
    631             $match = ( $max_width == $value ); 
    632         elseif ( '!=' == $operator ) : 
    633             $match = ( $max_width != $value ); 
    634         elseif ( '>=' == $operator ) : 
    635             $match = ( $max_width >= $value ); 
    636         elseif ( '<=' == $operator ) : 
    637             $match = ( $max_width <= $value ); 
    638         endif; 
    639  
    640         return $match; 
    641  
    642     } 
    643  
    644  
    645     /** 
    646      * Height. 
    647      * 
    648      * Match the condition value against the highest product in the cart. 
    649      * 
    650      * @since 1.0.0 
    651      * 
    652      * @param   bool    $match     Current match value. 
    653      * @param   string  $operator  Operator selected by the user in the condition row. 
    654      * @param   mixed   $value     Value given by the user in the condition row. 
    655      * @return  bool               Matching result, true if results match, otherwise false. 
    656      */ 
    657     public function wafs_match_condition_height( $match, $operator, $value ) { 
    658  
    659         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    660  
    661         foreach ( WC()->cart->cart_contents as $product ) : 
    662  
    663             if ( true == $product['data']->variation_has_height ) : 
    664                 $height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) ); 
    665             else : 
    666                 $height[] = ( get_post_meta( $product['product_id'], '_height', true ) ); 
    667             endif; 
    668  
    669         endforeach; 
    670  
    671         $max_height = max( $height ); 
    672  
    673         if ( '==' == $operator ) : 
    674             $match = ( $max_height == $value ); 
    675         elseif ( '!=' == $operator ) : 
    676             $match = ( $max_height != $value ); 
    677         elseif ( '>=' == $operator ) : 
    678             $match = ( $max_height >= $value ); 
    679         elseif ( '<=' == $operator ) : 
    680             $match = ( $max_height <= $value ); 
    681         endif; 
    682  
    683         return $match; 
    684  
    685     } 
    686  
    687  
    688     /** 
    689      * Length. 
    690      * 
    691      * Match the condition value against the lenghtiest product in the cart. 
    692      * 
    693      * @since 1.0.0 
    694      * 
    695      * @param   bool    $match     Current match value. 
    696      * @param   string  $operator  Operator selected by the user in the condition row. 
    697      * @param   mixed   $value     Value given by the user in the condition row. 
    698      * @return  bool               Matching result, true if results match, otherwise false. 
    699      */ 
    700     public function wafs_match_condition_length( $match, $operator, $value ) { 
    701  
    702         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    703  
    704         foreach ( WC()->cart->cart_contents as $product ) : 
    705  
    706             if ( true == $product['data']->variation_has_length ) : 
    707                 $length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) ); 
    708             else : 
    709                 $length[] = ( get_post_meta( $product['product_id'], '_length', true ) ); 
    710             endif; 
    711  
    712         endforeach; 
    713  
    714         $max_length = max( $length ); 
    715  
    716         if ( '==' == $operator ) : 
    717             $match = ( $max_length == $value ); 
    718         elseif ( '!=' == $operator ) : 
    719             $match = ( $max_length != $value ); 
    720         elseif ( '>=' == $operator ) : 
    721             $match = ( $max_length >= $value ); 
    722         elseif ( '<=' == $operator ) : 
    723             $match = ( $max_length <= $value ); 
    724         endif; 
    725  
    726         return $match; 
    727  
    728     } 
    729  
    730  
    731     /** 
    732      * Product stock. 
    733      * 
    734      * Match the condition value against all cart products stock. 
    735      * 
    736      * @since 1.0.0 
    737      * 
    738      * @param   bool    $match     Current match value. 
    739      * @param   string  $operator  Operator selected by the user in the condition row. 
    740      * @param   mixed   $value     Value given by the user in the condition row. 
    741      * @return  bool               Matching result, true if results match, otherwise false. 
    742      */ 
    743     public function wafs_match_condition_stock( $match, $operator, $value ) { 
    744  
    745         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) return $match; 
    746  
    747         foreach ( WC()->cart->cart_contents as $product ) : 
    748  
    749             $product_id = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id']; 
    750             $stock[]    = get_post_meta( $product_id, '_stock', true ); 
    751  
    752         endforeach; 
    753  
    754         $min_stock = min( $stock ); 
    755  
    756         if ( '==' == $operator ) : 
    757             $match = ( $min_stock == $value ); 
    758         elseif ( '!=' == $operator ) : 
    759             $match = ( $min_stock != $value ); 
    760         elseif ( '>=' == $operator ) : 
    761             $match = ( $min_stock >= $value ); 
    762         elseif ( '<=' == $operator ) : 
    763             $match = ( $min_stock <= $value ); 
    764         endif; 
    765  
    766         return $match; 
    767  
    768     } 
    769  
    770  
    771     /** 
    772      * Stock status. 
    773      * 
    774      * Match the condition value against all cart products stock statuses. 
    775      * 
    776      * @since 1.0.0 
    777      * 
    778      * @param   bool    $match     Current match value. 
    779      * @param   string  $operator  Operator selected by the user in the condition row. 
    780      * @param   mixed   $value     Value given by the user in the condition row. 
    781      * @return  bool               Matching result, true if results match, otherwise false. 
    782      */ 
    783     public function wafs_match_condition_stock_status( $match, $operator, $value ) { 
    784  
    785         if ( ! isset( WC()->cart ) ) return $match; 
    786  
    787         if ( '==' == $operator ) : 
    788  
    789             $match = true; 
    790             foreach ( WC()->cart->cart_contents as $product ) : 
    791                 if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value ) { 
    792                     $match = false; 
    793                 } 
    794             endforeach; 
    795  
    796         elseif ( '!=' == $operator ) : 
    797  
    798             $match = true; 
    799             foreach ( WC()->cart->cart_contents as $product ) : 
    800                 if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value ) { 
    801                     $match = false; 
    802                 } 
    803             endforeach; 
    804  
    805         endif; 
    806  
    807         return $match; 
    808  
    809     } 
    810  
    811  
    812     /** 
    813      * Category. 
    814      * 
    815      * Match the condition value against all the cart products category. 
    816      * With this condition, all the products in the cart must have the given class. 
    817      * 
    818      * @since 1.0.0 
    819      * 
    820      * @param   bool    $match     Current match value. 
    821      * @param   string  $operator  Operator selected by the user in the condition row. 
    822      * @param   mixed   $value     Value given by the user in the condition row. 
    823      * @return  bool               Matching result, true if results match, otherwise false. 
    824      */ 
    825     public function wafs_match_condition_category( $match, $operator, $value ) { 
    826  
    827         if ( ! isset( WC()->cart ) ) return $match; 
    828  
    829         $match = true; 
    830  
    831         if ( '==' == $operator ) : 
    832  
    833             foreach ( WC()->cart->cart_contents as $product ) : 
    834  
    835                 if ( ! has_term( $value, 'product_cat', $product['product_id'] ) ) : 
    836                     $match = false; 
    837                 endif; 
    838  
    839             endforeach; 
    840  
    841         elseif ( '!=' == $operator ) : 
    842  
    843             foreach ( WC()->cart->cart_contents as $product ) : 
    844  
    845                 if ( has_term( $value, 'product_cat', $product['product_id'] ) ) : 
    846                     $match = false; 
    847                 endif; 
    848  
    849             endforeach; 
    850  
    851         endif; 
    852  
    853         return $match; 
    854  
    855     } 
    856  
    857  
    858124} 
  • woocommerce-advanced-free-shipping/trunk/includes/class-wafs-method.php

    r1483190 r1609491  
    1919        $this->method_title       = __( 'Advanced Free Shipping', 'woocommerce-advanced-free-shipping' ); 
    2020        $this->method_description = __( 'Configure Advanced Free Shipping' ); 
    21  
    22         $this->matched_methods = $this->wafs_match_methods(); 
    2321 
    2422        $this->init(); 
     
    6462        $methods = wafs_get_rates(); 
    6563 
    66         $matched_methods = ''; 
     64        $matched_methods = false; 
    6765        foreach ( $methods as $method ) : 
    6866 
    6967            $condition_groups = get_post_meta( $method->ID, '_wafs_shipping_method_conditions', true ); 
    7068 
    71             // Check if method conditions match 
    72             $match = $this->wafs_match_conditions( $condition_groups ); 
    73  
    74             // Add (single) match to parameter 
    75             if ( true == $match ) : 
     69            // Check if conditions match 
     70            if ( wpc_match_conditions( $condition_groups, array( 'context' => 'wafs' ) ) ) : 
    7671                $matched_methods = $method->ID; 
    7772            endif; 
     
    8075 
    8176        return $matched_methods; 
    82  
    83     } 
    84  
    85  
    86     /** 
    87      * Match conditions. 
    88      * 
    89      * Method to check all condition groups and conditions if they match their rules. 
    90      * 
    91      * @since 1.0.0 
    92      * 
    93      * @param   array  $condition_groups  All condition groups set by the user. 
    94      * @return  bool                      true if one of the conditions groups matches. 
    95      */ 
    96     public function wafs_match_conditions( $condition_groups = array() ) { 
    97  
    98         if ( empty( $condition_groups ) ) return false; 
    99  
    100         foreach ( $condition_groups as $condition_group => $conditions ) : 
    101  
    102             $match_condition_group = true; 
    103  
    104             foreach ( $conditions as $condition ) : 
    105  
    106                 $match = apply_filters( 'wafs_match_condition_' . $condition['condition'], false, $condition['operator'], $condition['value'] ); 
    107  
    108                 if ( false == $match ) : 
    109                     $match_condition_group = false; 
    110                 endif; 
    111  
    112             endforeach; 
    113  
    114             // return true if one condition group matches 
    115             if ( true == $match_condition_group ) : 
    116                 return true; 
    117             endif; 
    118  
    119         endforeach; 
    120  
    121         return false; 
    12277 
    12378    } 
     
    166121 
    167122        ob_start(); 
    168  
    169             /** 
    170              * Load conditions table file 
    171              */ 
    172123            require_once plugin_dir_path( __FILE__ ) . 'admin/views/conditions-table.php'; 
    173  
    174124        return ob_get_clean(); 
    175  
    176     } 
    177  
    178  
    179     /** 
    180      * Validate table. 
    181      * 
    182      * Condition table does not need validation, so always return false. 
    183      * 
    184      * @since 1.0.0 
    185      * 
    186      * @param   mixed  $key  Key. 
    187      * @return  bool         Validation. 
    188      */ 
    189     public function validate_additional_conditions_table_field( $key ) { 
    190  
    191         return false; 
    192125 
    193126    } 
     
    205138    public function calculate_shipping( $package = array() ) { 
    206139 
    207         if ( false == $this->matched_methods || 'no' == $this->enabled ) return; 
     140        if ( $this->enabled == 'no' ) { 
     141            return; 
     142        } 
    208143 
    209         $method_args = get_post_meta( $this->matched_methods, '_wafs_shipping_method', true ); 
     144        if ( ! $matched_rate = $this->wafs_match_methods() ) { 
     145            return; 
     146        } 
     147 
     148        $method_args = get_post_meta( $matched_rate, '_wafs_shipping_method', true ); 
    210149        $label       = ! empty( $method_args['shipping_title'] ) ? $method_args['shipping_title'] : __( 'Free Shipping', 'woocommerce-advanced-free-shipping' ); 
    211150 
  • woocommerce-advanced-free-shipping/trunk/includes/class-wafs-post-type.php

    r1483190 r1609491  
    2727        add_action( 'add_meta_boxes', array( $this, 'post_type_meta_box' ) ); 
    2828        add_action( 'save_post', array( $this, 'save_meta' ) ); 
    29         add_action( 'save_post', array( $this, 'save_condition_meta' ) ); 
    3029 
    3130        // Edit user messages 
     
    4847 
    4948        $labels = array( 
    50             'name'               => __( 'Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ), 
    51             'singular_name'      => __( 'Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
     49            'name'               => __( 'Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ), 
     50            'singular_name'      => __( 'Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
    5251            'add_new'            => __( 'Add New', 'woocommerce-advanced-free-shipping' ), 
    53             'add_new_item'       => __( 'Add New Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
    54             'edit_item'          => __( 'Edit Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
    55             'new_item'           => __( 'New Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
    56             'view_item'          => __( 'View Advanced Free Shipping method', 'woocommerce-advanced-free-shipping' ), 
    57             'search_items'       => __( 'Search Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ), 
    58             'not_found'          => __( 'No Advanced Free Shipping methods', 'woocommerce-advanced-free-shipping' ), 
    59             'not_found_in_trash' => __( 'No Advanced Free Shipping methods found in Trash', 'woocommerce-advanced-free-shipping' ), 
     52            'add_new_item'       => __( 'Add New Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
     53            'edit_item'          => __( 'Edit Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
     54            'new_item'           => __( 'New Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
     55            'view_item'          => __( 'View Advanced Free Shipping rate', 'woocommerce-advanced-free-shipping' ), 
     56            'search_items'       => __( 'Search Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ), 
     57            'not_found'          => __( 'No Advanced Free Shipping rates', 'woocommerce-advanced-free-shipping' ), 
     58            'not_found_in_trash' => __( 'No Advanced Free Shipping rates found in Trash', 'woocommerce-advanced-free-shipping' ), 
    6059        ); 
    6160 
     
    9594        $messages['wafs'] = array( 
    9695            0  => '', 
    97             1  => __( 'Free shipping method updated.', 'woocommerce-advanced-free-shipping' ), 
     96            1  => __( 'Free shipping rate updated.', 'woocommerce-advanced-free-shipping' ), 
    9897            2  => __( 'Custom field updated.', 'woocommerce-advanced-free-shipping' ), 
    9998            3  => __( 'Custom field deleted.', 'woocommerce-advanced-free-shipping' ), 
    100             4  => __( 'Free shipping method updated.', 'woocommerce-advanced-free-shipping' ), 
    101             6  => __( 'Free shipping method published.', 'woocommerce-advanced-free-shipping' ), 
    102             7  => __( 'Free shipping method saved.', 'woocommerce-advanced-free-shipping' ), 
    103             8  => __( 'Free shipping method submitted.', 'woocommerce-advanced-free-shipping' ), 
     99            4  => __( 'Free shipping rate updated.', 'woocommerce-advanced-free-shipping' ), 
     100            6  => __( 'Free shipping rate published.', 'woocommerce-advanced-free-shipping' ), 
     101            7  => __( 'Free shipping rate saved.', 'woocommerce-advanced-free-shipping' ), 
     102            8  => __( 'Free shipping rate submitted.', 'woocommerce-advanced-free-shipping' ), 
    104103            9  => sprintf( 
    105104                __( 'Free shipping method scheduled for: <strong>%1$s</strong>.', 'woocommerce-advanced-free-shipping' ), 
    106105                date_i18n( __( 'M j, Y @ G:i', 'woocommerce-advanced-free-shipping' ), strtotime( $post->post_date ) ) 
    107106            ), 
    108             10 => __( 'Free shipping method draft updated.', 'woocommerce-advanced-free-shipping' ), 
     107            10 => __( 'Free shipping rate draft updated.', 'woocommerce-advanced-free-shipping' ), 
    109108        ); 
    110109 
    111110        if ( 'wafs' == $post_type ) : 
    112             $overview_link = admin_url( 'admin.php?page=wc-settings&tab=shipping&section=wafs_free_shipping_method' ); 
     111            $overview_link = admin_url( 'admin.php?page=wc-settings&tab=shipping&section=advanced_free_shipping' ); 
    113112 
    114113            $overview                    = sprintf( ' <a href="%s">%s</a>', esc_url( $overview_link ), __( 'Return to overview.', 'woocommerce-advanced-free-shipping' ) ); 
     
    149148     */ 
    150149    public function render_wafs_conditions() { 
    151  
    152         /** 
    153          * Load meta box conditions view. 
    154          */ 
    155150        require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-conditions.php'; 
    156  
    157151    } 
    158152 
     
    166160     */ 
    167161    public function render_wafs_settings() { 
    168  
    169         /** 
    170          * Load meta box settings view 
    171          */ 
    172162        require_once plugin_dir_path( __FILE__ ) . 'admin/views/meta-box-settings.php'; 
    173  
    174     } 
    175  
    176  
    177     /** 
    178      * Save conditions meta box. 
    179      * 
    180      * Validate and save post meta from conditions meta box. 
    181      * 
    182      * @since 1.0.0 
    183      */ 
    184     public function save_condition_meta( $post_id ) { 
     163    } 
     164 
     165 
     166    /** 
     167     * Save settings meta box. 
     168     * 
     169     * Validate and save post meta from settings meta box. 
     170     * 
     171     * @since 1.0.0 
     172     */ 
     173    public function save_meta( $post_id ) { 
    185174 
    186175        if ( ! isset( $_POST['wafs_settings_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['wafs_settings_meta_box_nonce'], 'wafs_settings_meta_box' ) ) : 
     
    196185        endif; 
    197186 
    198         $shipping_method_conditions = $_POST['conditions']; 
    199  
    200         update_post_meta( $post_id, '_wafs_shipping_method_conditions', $shipping_method_conditions ); 
    201  
    202     } 
    203  
    204  
    205     /** 
    206      * Save settings meta box. 
    207      * 
    208      * Validate and save post meta from settings meta box. 
    209      * 
    210      * @since 1.0.0 
    211      */ 
    212     public function save_meta( $post_id ) { 
    213  
    214         if ( ! isset( $_POST['wafs_settings_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['wafs_settings_meta_box_nonce'], 'wafs_settings_meta_box' ) ) : 
    215             return $post_id; 
    216         endif; 
    217  
    218         if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) : 
    219             return $post_id; 
    220         endif; 
    221  
    222         if ( ! current_user_can( 'manage_woocommerce' ) ) : 
    223             return $post_id; 
    224         endif; 
    225  
    226187        $shipping_method = array_map( 'sanitize_text_field', $_POST['_wafs_shipping_method'] ); 
    227  
    228188        update_post_meta( $post_id, '_wafs_shipping_method', $shipping_method ); 
     189 
     190        // Save sanitized conditions 
     191        update_post_meta( $post_id, '_wafs_shipping_method_conditions', wpc_sanitize_conditions( $_POST['conditions'] ) ); 
    229192 
    230193    } 
  • woocommerce-advanced-free-shipping/trunk/includes/core-functions.php

    r1483190 r1609491  
    2020        'orderby'                => 'menu_order', 
    2121        'order'                  => 'ASC', 
    22         'update_post_term_cache' => false 
     22        'update_post_term_cache' => false, 
     23        'no_found_rows'          => true, 
    2324    ) ); 
    2425 
    2526    $rates_query    = new WP_Query( $query_args ); 
    26     $shipping_rates = $rates_query->get_posts(); 
     27    $shipping_rates = $rates_query->posts; 
    2728 
    2829    return apply_filters( 'woocommerce_advanced_free_shipping_get_rates', $shipping_rates ); 
    2930 
    3031} 
     32 
     33/************************************************************** 
     34 * Backwards compatibility for WP Conditions 
     35 *************************************************************/ 
     36 
     37/** 
     38 * Add the filters required for backwards-compatibility for the matching functionality. 
     39 * 
     40 * @since 1.1.0 
     41 */ 
     42function wafs_add_bc_filter_condition_match( $match, $condition, $operator, $value, $args = array() ) { 
     43 
     44    if ( ! isset( $args['context'] ) || $args['context'] != 'wafs' ) { 
     45        return $match; 
     46    } 
     47 
     48    if ( has_filter( 'wafs_match_condition_' . $condition ) ) { 
     49        $match = apply_filters( 'wafs_match_condition_' . $condition, $match = false, $operator, $value ); 
     50    } 
     51 
     52    return $match; 
     53 
     54} 
     55add_action( 'wp-conditions\condition\match', 'wafs_add_bc_filter_condition_match', 10, 5 ); 
     56 
     57 
     58/** 
     59 * Add condition descriptions of custom conditions. 
     60 * 
     61 * @since 1.1.0 
     62 */ 
     63function wafs_add_bc_filter_condition_descriptions( $descriptions ) { 
     64    return apply_filters( 'wafs_descriptions', $descriptions ); 
     65} 
     66add_filter( 'wp-conditions\condition_descriptions', 'wafs_add_bc_filter_condition_descriptions' ); 
     67 
     68 
     69/** 
     70 * Add custom field BC. 
     71 * 
     72 * @since 1.1.0 
     73 */ 
     74function wafs_add_bc_action_custom_fields( $type, $args ) { 
     75 
     76    if ( has_action( 'woocommerce_advanced_fees_condition_value_field_type_' . $type ) ) { 
     77        do_action( 'woocommerce_advanced_fees_condition_value_field_type_' . $args['type'], $args ); 
     78    } 
     79 
     80} 
     81add_action( 'wp-conditions\html_field_hook', 'wafs_add_bc_action_custom_fields' ); 
  • woocommerce-advanced-free-shipping/trunk/readme.txt

    r1491641 r1609491  
    33Tags: woocommerce, shipping, woocommerce shipping, woocommerce free shipping, woocommerce free, woocommerce advanced free shipping, wc free shipping, wc shipping, advanced shipping, pro shipping, table rate shipping, country shipping, free shipping 
    44Requires at least: 4.0 
    5 Tested up to: 4.6 
    6 Stable tag: 1.0.11 
     5Tested up to: 4.7.2 
     6Stable tag: 1.1.0 
    77License: GPLv3 or later 
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html 
     
    1515*Conditions like:* 
    1616 
    17 - Cart total 
     17- Subtotal 
     18- User role 
    1819- Country 
    1920- Zip code 
     
    4546> View [WooCommerce Advanced Shipping](http://codecanyon.net/item/woocommerce-advanced-shipping/8634573) 
    4647 
    47 **Translations, feature requests, ratings and donations are welcome and appreciated!** 
     48**Showing a free shipping threshold message** 
     49There are a few plugins out there that add a message when someone hasn't reached the free shipping threshold yet. These plugin work on the 'Free shipping' option that is provided in WooCommerce by default. 
     50It is unlikely that these plugins will work out of the box with Advanced Free Shipping due to the complexity of the conditional logic. 
     51 
     52In case you do want to show this kind of message, The [Advanced Messages for WooCommerce](https://shopplugins.com/plugins/woocommerce-advanced-messages/ ) plugin allows you to setup a message with the same type of conditions, allowing you to setup the messages according to the same needs as the free shipping options. 
     53 
     54**Translations, feature requests and ratings are welcome and appreciated!** 
    4855 
    4956**Translations** 
     
    6572 
    6673== Changelog == 
     74 
     75= 1.1.0 - 06-03-2017 = IMPORTANT NOTE - As of this version, the plugin requires PHP 5.3 to function 
     76 
     77* [Fix] - Allow variations to be set (and make them working) with the 'contains product' condition 
     78* [Fix] - Prevent duplicate DB query 
     79* [Improvement] - BIG refactor of the backend conditions - please verify your setup if using custom coded condition 
     80* [Improvement] - Smoother User Experience with conditions 
     81    - Instant adding of conditions / condition groups 
     82    - Only show valid operator options 
     83    - Instantly show condition descriptions 
     84    - Deleting entire condition groups 
     85    - Duplicate condition groups 
     86* [Improvement] - WC 2.7 compatibility changes 
    6787 
    6888= 1.0.11 - 05-09-2016 = 
  • woocommerce-advanced-free-shipping/trunk/woocommerce-advanced-free-shipping.php

    r1490367 r1609491  
    44 * Plugin URI:      https://wordpress.org/plugins/woocommerce-advanced-free-shipping/ 
    55 * Description:     WooCommerce Advanced Free Shipping is an plugin which allows you to set up advanced free shipping conditions. 
    6  * Version:         1.0.11 
     6 * Version:         1.1.0 
    77 * Author:          Jeroen Sormani 
    88 * Author URI:      http://jeroensormani.com/ 
     
    4949     * @var string $version Plugin version number. 
    5050     */ 
    51     public $version = '1.0.11'; 
     51    public $version = '1.1.0'; 
    5252 
    5353 
     
    8989        endif; 
    9090 
    91         $this->init(); 
    92  
    9391    } 
    9492 
     
    124122    public function init() { 
    125123 
     124        if ( version_compare( PHP_VERSION, '5.3', 'lt' ) ) { 
     125            return add_action( 'admin_notices', array( $this, 'php_version_notice' ) ); 
     126        } 
     127 
    126128        // Add hooks/filters 
    127129        $this->hooks(); 
     
    133135        $this->update(); 
    134136 
     137        require_once plugin_dir_path( __FILE__ ) . '/libraries/wp-conditions/functions.php'; 
     138 
    135139        // Functions 
    136140        require_once plugin_dir_path( __FILE__ ) . 'includes/core-functions.php'; 
     
    158162         */ 
    159163        if ( is_admin() ) : 
    160             require_once plugin_dir_path( __FILE__ ) . 'includes/admin/admin-functions.php'; 
    161  
    162164            require_once plugin_dir_path( __FILE__ ) . 'includes/admin/class-wafs-admin.php'; 
    163165            $this->admin = new WAFS_Admin(); 
     166            $this->admin->init(); 
    164167        endif; 
    165168 
     
    213216 
    214217        // Add shipping method 
    215         add_action( 'woocommerce_shipping_methods', array( $this, 'wafs_add_shipping_method' ) ); 
     218        add_filter( 'woocommerce_shipping_methods', array( $this, 'wafs_add_shipping_method' ) ); 
    216219 
    217220    } 
     
    270273 
    271274    /** 
    272      * Enqueue scripts. 
    273      * 
    274      * Enqueue javascript and stylesheets to the admin area. 
    275      * 
    276      * @since 1.0.0 
    277      */ 
    278     public function wafs_admin_enqueue_scripts() { 
    279  
    280         _deprecated_function( __FUNCTION__, '1.0.8', 'WAFS()->admin->admin_enqueue_script()' ); 
    281  
    282     } 
    283  
     275     * Display PHP 5.3 required notice. 
     276     * 
     277     * Display a notice when the required PHP version is not met. 
     278     * 
     279     * @since 1.0.6 
     280     */ 
     281    public function php_version_notice() { 
     282 
     283        ?><div class='updated'> 
     284        <p><?php echo sprintf( __( 'Advanced Free Shipping requires PHP 5.3 or higher and your current PHP version is %s. Please (contact your host to) update your PHP version.', 'woocommerce-advanced-messages' ), PHP_VERSION ); ?></p> 
     285        </div><?php 
     286 
     287    } 
    284288 
    285289} 
     
    308312endif; 
    309313 
    310 WAFS(); 
     314WAFS()->init(); 
Note: See TracChangeset for help on using the changeset viewer.