WordPress.org

Plugin Directory

Changeset 1607412


Ignore:
Timestamp:
03/03/17 20:13:53 (10 months ago)
Author:
sormano
Message:

Versioning 1.1.0

Location:
advanced-shipping-validation-for-woocommerce
Files:
78 added
3 deleted
18 edited
18 copied

Legend:

Unmodified
Added
Removed
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/advanced-shipping-validation-for-woocommerce.php

    r1493453 r1607412  
    44 * Plugin URI:      http://jeroensormani.com/ 
    55 * Description:     Setup shipping validation rules based on your own conditions. Show customers a specific message why they can't continue to checkout. 
    6  * Version:         1.0.3 
     6 * Version:         1.1.0 
    77 * Author:          Jeroen Sormani 
    88 * Author URI:      http://jeroensormani.com/ 
     
    3030     * @var string $version Plugin version number. 
    3131     */ 
    32     public $version = '1.0.3'; 
     32    public $version = '1.1.0'; 
    3333 
    3434 
     
    7070        endif; 
    7171 
    72         // Initialize plugin parts 
    73         $this->init(); 
    74  
    7572        do_action( 'woocommerce_advanced_shipping_validation_init' ); 
    7673 
     
    9087    public static function instance() { 
    9188 
    92         if ( is_null( self::$instance ) ) : 
     89        if ( is_null( self::$instance ) ) { 
    9390            self::$instance = new self(); 
    94         endif; 
     91        } 
    9592 
    9693        return self::$instance; 
     
    107104     */ 
    108105    public function init() { 
     106 
     107        if ( version_compare( PHP_VERSION, '5.3', 'lt' ) ) { 
     108            return add_action( 'admin_notices', array( $this, 'php_version_notice' ) ); 
     109        } 
     110 
     111        require_once plugin_dir_path( __FILE__ ) . '/libraries/wp-conditions/functions.php'; 
    109112 
    110113        /** 
     
    122125        // AJAX 
    123126        if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) : 
    124  
    125             require_once plugin_dir_path( __FILE__ ) . '/includes/admin/admin-functions.php'; 
    126  
    127             /** 
    128              * Load ajax methods 
    129              */ 
    130127            require_once plugin_dir_path( __FILE__ ) . '/includes/class-wcasv-ajax.php'; 
    131128            $this->ajax = new WCASV_Ajax(); 
    132  
    133129        endif; 
    134130 
    135131        // Admin 
    136132        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) : 
    137  
    138             require_once plugin_dir_path( __FILE__ ) . '/includes/admin/admin-functions.php'; 
    139  
    140             /** 
    141              * Admin class. 
    142              */ 
    143133            require_once plugin_dir_path( __FILE__ ) . '/includes/admin/class-wcasv-admin.php'; 
    144134            $this->admin = new WCASV_Admin(); 
    145  
    146  
    147135        endif; 
    148136 
     
    174162 
    175163 
     164    /** 
     165     * Display PHP 5.3 required notice. 
     166     * 
     167     * Display a notice when the required PHP version is not met. 
     168     * 
     169     * @since 1.0.6 
     170     */ 
     171    public function php_version_notice() { 
     172 
     173        ?><div class='updated'> 
     174            <p><?php echo sprintf( __( 'Advanced Shipping Validation 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> 
     175        </div><?php 
     176 
     177    } 
     178 
     179 
    176180} 
    177181 
     
    198202 
    199203endif; 
    200 Woocommerce_Advanced_Shipping_Validation(); 
     204Woocommerce_Advanced_Shipping_Validation()->init(); 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/assets/admin/css/woocommerce-advanced-shipping-validation.css

    r1485561 r1607412  
    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-shipping_validation .misc-pub-visibility#visibility{display:none}.wcasv-option label{display:inline-block;width:150px}.wcasv-option input{line-height:19px;width:190px}.wcasv_settings_meta_box .wcasv-description{float:none;line-height:19px}.wcasv_settings_meta_box #validation-message{max-width:75%;width:75%;vertical-align:top}.wcasv_conditions_meta_box>p:first-child+div>.or-match{display:none} 
     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"}.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-shipping_validation .misc-pub-visibility#visibility{display:none}.wcasv-option label{display:inline-block;width:150px}.wcasv-option input{line-height:19px;width:190px}.wcasv_settings_meta_box .wcasv-description{float:none;line-height:19px}.wcasv_settings_meta_box #validation-message{max-width:75%;width:75%;vertical-align:top}.wcasv_conditions_meta_box>p:first-child+div>.or-match{display:none} 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/assets/admin/css/woocommerce-advanced-shipping-validation.scss

    r1485561 r1607412  
    1 @import 'parts/wp-conditions'; 
     1@import '../../../libraries/wp-conditions/assets/css/wp-conditions'; 
    22 
    33/* Hide visibility from admin */ 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/assets/admin/js/woocommerce-advanced-shipping-validation.js

    r1485561 r1607412  
    11jQuery( function( $ ) { 
    2  
    3     /************************************************************** 
    4      * WPC - 1.0.1 
    5      *************************************************************/ 
    6  
    7         // Add condition 
    8     $( document.body ).on( 'click', '.wpc-condition-add', function() { 
    9  
    10         var $this = $( this ); 
    11         var data = { 
    12             action: wpc.action_prefix + 'add_condition', 
    13             group: $( this ).attr( 'data-group' ), 
    14             nonce: wpc.nonce 
    15         }; 
    16         var condition_group = $this.parents( '.wpc-conditions' ).find( '.wpc-condition-group-' + data.group ); 
    17  
    18         var loading_icon = '<div class="wpc-condition-wrap loading"></div>'; 
    19         condition_group.append( loading_icon ).children( ':last' ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } }); 
    20  
    21         $.post( ajaxurl, data, function( response ) { 
    22             condition_group.find( ' .wpc-condition-wrap.loading' ).first().replaceWith( function() { 
    23                 return $( response ).hide().fadeIn( 'normal' ); 
    24             }); 
    25         }); 
    26  
    27     }); 
    28  
    29     // Delete condition 
    30     $( document.body ).on( 'click', '.wpc-condition-delete', function() { 
    31  
    32         if ( $( this ).closest( '.wpc-condition-group' ).children( '.wpc-condition-wrap' ).length == 1 ) { 
    33             $( this ).closest( '.wpc-condition-group' ).fadeOut( 'normal', function() { 
    34                 $( this ).next( '.or-text' ).remove(); 
    35                 $( this ).remove(); 
    36             }); 
    37         } else { 
    38             $( this ).closest( '.wpc-condition-wrap' ).slideUp( 'fast', function() { $( this ).remove(); }); 
    39         } 
    40  
    41     }); 
    42  
    43     // Add condition group 
    44     $( document.body ).on( 'click', '.wpc-condition-group-add', function() { 
    45  
    46         var condition_group_loading = '<div class="wpc-condition-group loading"></div>'; 
    47         var conditions = $( this ).prev( '.wpc-conditions' ); 
    48         var data = { 
    49             action: wpc.action_prefix + 'add_condition_group', 
    50             group:  parseInt( $( this ).prev( '.wpc-conditions' ).find( '.wpc-condition-group' ).length ), 
    51             nonce:  wpc.nonce 
    52         }; 
    53  
    54         // Display loading icon 
    55         conditions.append( condition_group_loading ).children( ':last' ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } }); 
    56  
    57         // Insert condition group 
    58         $.post( ajaxurl, data, function( response ) { 
    59             conditions.find( '.wpc-condition-group.loading' ).first().replaceWith( function() { 
    60                 return $( response ).hide().fadeIn( 'normal' ); 
    61             }); 
    62         }); 
    63  
    64     }); 
    65  
    66     // Update condition values 
    67     $( document.body ).on( 'change', '.wpc-condition', function () { 
    68  
    69         var loading_wrap = '<span style="width: 30%; border: 1px solid transparent; display: inline-block;">&nbsp;</span>'; 
    70         var data = { 
    71             action:     wpc.action_prefix + 'update_condition_value', 
    72             id:         $( this ).attr( 'data-id' ), 
    73             group:      $( this ).attr( 'data-group' ), 
    74             condition:  $( this ).val(), 
    75             nonce:      wpc.nonce 
    76         }; 
    77         var condition_group = $( this ).parents( '.wpc-conditions' ).find( '.wpc-condition-group-' + data.group ); 
    78         var replace = '.wpc-value-wrap-' + data.id; 
    79  
    80         // Loading icon 
    81         condition_group.find( replace ).html( loading_wrap ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } }); 
    82  
    83         // Replace value field 
    84         $.post( ajaxurl, data, function( response ) { 
    85             condition_group.find( replace ).replaceWith( response ); 
    86             $( document.body ).trigger( 'wc-enhanced-select-init' ); 
    87         }); 
    88  
    89         // Update condition description 
    90         var description = { 
    91             action:     wpc.action_prefix + 'update_condition_description', 
    92             condition:  data.condition, 
    93             nonce:      wpc.nonce 
    94         }; 
    95  
    96         $.post( ajaxurl, description, function( description_response ) { 
    97             condition_group.find( replace + ' ~ .wpc-description' ).replaceWith( description_response ); 
    98             // Tooltip 
    99             $( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 200 }); 
    100         }) 
    101  
    102     }); 
    103  
    104     // Sortable 
    105     $( '.wpc-conditions-post-table tbody' ).sortable({ 
    106         items:                  'tr', 
    107         handle:                 '.sort', 
    108         cursor:                 'move', 
    109         axis:                   'y', 
    110         scrollSensitivity:      40, 
    111         forcePlaceholderSize:   true, 
    112         helper:                 'clone', 
    113         opacity:                0.65, 
    114         placeholder:            'wc-metabox-sortable-placeholder', 
    115         start:function(event,ui){ 
    116             ui.item.css( 'background-color','#f6f6f6' ); 
    117         }, 
    118         stop:function(event,ui){ 
    119             ui.item.removeAttr( 'style' ); 
    120         }, 
    121         update: function(event, ui) { 
    122  
    123             $table  = $( this ).closest( 'table' ); 
    124             $table.block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } }); 
    125             // Update fee order 
    126             var data = { 
    127                 action: wpc.action_prefix + 'save_post_order', 
    128                 form:   $( this ).closest( 'form' ).serialize(), 
    129                 nonce:  wpc.nonce 
    130             }; 
    131  
    132             $.post( ajaxurl, data, function( response ) { 
    133                 $( '.wpc-conditions-post-table tbody tr:even' ).addClass( 'alternate' ); 
    134                 $( '.wpc-conditions-post-table tbody tr:odd' ).removeClass( 'alternate' ); 
    135                 $table.unblock(); 
    136             }); 
    137         } 
    138     }); 
    139  
    1402 
    1413    // Price input validation / error handling 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/assets/admin/js/woocommerce-advanced-shipping-validation.min.js

    r1485561 r1607412  
    1 jQuery(function($){$(document.body).on("click",".wpc-condition-add",function(){var o=$(this),n={action:wpc.action_prefix+"add_condition",group:$(this).attr("data-group"),nonce:wpc.nonce},t=o.parents(".wpc-conditions").find(".wpc-condition-group-"+n.group),i='<div class="wpc-condition-wrap loading"></div>';t.append(i).children(":last").block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,n,function(o){t.find(" .wpc-condition-wrap.loading").first().replaceWith(function(){return $(o).hide().fadeIn("normal")})})}),$(document.body).on("click",".wpc-condition-delete",function(){1==$(this).closest(".wpc-condition-group").children(".wpc-condition-wrap").length?$(this).closest(".wpc-condition-group").fadeOut("normal",function(){$(this).next(".or-text").remove(),$(this).remove()}):$(this).closest(".wpc-condition-wrap").slideUp("fast",function(){$(this).remove()})}),$(document.body).on("click",".wpc-condition-group-add",function(){var o='<div class="wpc-condition-group loading"></div>',n=$(this).prev(".wpc-conditions"),t={action:wpc.action_prefix+"add_condition_group",group:parseInt($(this).prev(".wpc-conditions").find(".wpc-condition-group").length),nonce:wpc.nonce};n.append(o).children(":last").block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,t,function(o){n.find(".wpc-condition-group.loading").first().replaceWith(function(){return $(o).hide().fadeIn("normal")})})}),$(document.body).on("change",".wpc-condition",function(){var o='<span style="width: 30%; border: 1px solid transparent; display: inline-block;">&nbsp;</span>',n={action:wpc.action_prefix+"update_condition_value",id:$(this).attr("data-id"),group:$(this).attr("data-group"),condition:$(this).val(),nonce:wpc.nonce},t=$(this).parents(".wpc-conditions").find(".wpc-condition-group-"+n.group),i=".wpc-value-wrap-"+n.id;t.find(i).html(o).block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,n,function(o){t.find(i).replaceWith(o),$(document.body).trigger("wc-enhanced-select-init")});var c={action:wpc.action_prefix+"update_condition_description",condition:n.condition,nonce:wpc.nonce};$.post(ajaxurl,c,function(o){t.find(i+" ~ .wpc-description").replaceWith(o),$(".tips, .help_tip, .woocommerce-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})})}),$(".wpc-conditions-post-table tbody").sortable({items:"tr",handle:".sort",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(o,n){n.item.css("background-color","#f6f6f6")},stop:function(o,n){n.item.removeAttr("style")},update:function(o,n){$table=$(this).closest("table"),$table.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var t={action:wpc.action_prefix+"save_post_order",form:$(this).closest("form").serialize(),nonce:wpc.nonce};$.post(ajaxurl,t,function(o){$(".wpc-conditions-post-table tbody tr:even").addClass("alternate"),$(".wpc-conditions-post-table tbody tr:odd").removeClass("alternate"),$table.unblock()})}}),$(document.body).on("blur",".wcasv_input_price[type=text]",function(){$(".wc_error_tip").fadeOut("100",function(){$(this).remove()})}).on("keyup change",".wcasv_input_price[type=text]",function(){var o=$(this).val(),n=new RegExp("[^-0-9%*\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),t=o.replace(n,"");o!==t?($(this).val(t),$(document.body).triggerHandler("wc_add_error_tip",[$(this),"i18n_mon_decimal_error"])):$(document.body).triggerHandler("wc_remove_error_tip",[$(this),"i18n_mon_decimal_error"])})}); 
     1jQuery(function($){$(document.body).on("blur",".wcasv_input_price[type=text]",function(){$(".wc_error_tip").fadeOut("100",function(){$(this).remove()})}).on("keyup change",".wcasv_input_price[type=text]",function(){var e=$(this).val(),r=new RegExp("[^-0-9%*\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),t=e.replace(r,"");e!==t?($(this).val(t),$(document.body).triggerHandler("wc_add_error_tip",[$(this),"i18n_mon_decimal_error"])):$(document.body).triggerHandler("wc_remove_error_tip",[$(this),"i18n_mon_decimal_error"])})}); 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/codeoversight.yml

    r1420767 r1607412  
    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 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/admin/class-wcasv-admin-settings.php

    r1493453 r1607412  
    2020     * @since 1.0.0 
    2121     */ 
    22     public function __construct() { 
    23  
    24         add_action( 'admin_init', array( $this, 'init' ), 20 ); 
    25  
    26     } 
     22    public function __construct() {} 
    2723 
    2824 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/admin/class-wcasv-admin.php

    r1485561 r1607412  
    4444        require_once plugin_dir_path( __FILE__ ) . 'class-wcasv-admin-settings.php'; 
    4545        $this->settings = new WCASV_Admin_Settings(); 
     46        $this->settings->init(); 
    4647 
    4748        global $pagenow; 
     
    8283    public function admin_enqueue_scripts() { 
    8384 
     85        // Style script 
     86        wp_register_style( 'woocommerce-advanced-shipping-validation', plugins_url( 'assets/admin/css/woocommerce-advanced-shipping-validation.css', Woocommerce_Advanced_Shipping_Validation()->file ), array(), Woocommerce_Advanced_Shipping_Validation()->version ); 
     87 
     88        // Javascript 
     89        wp_register_script( 'woocommerce-advanced-shipping-validation', plugins_url( 'assets/admin/js/woocommerce-advanced-shipping-validation.min.js', Woocommerce_Advanced_Shipping_Validation()->file ), array( 'jquery', 'jquery-ui-sortable' ), Woocommerce_Advanced_Shipping_Validation()->version, true ); 
     90 
     91        wp_localize_script( 'woocommerce-advanced-shipping-validation-js', 'wpc', array( 
     92            'nonce'         => wp_create_nonce( 'wpc-ajax-nonce' ), 
     93            'action_prefix' => 'wcasv_', 
     94            'asset_url'     => plugins_url( 'assets/', Woocommerce_Advanced_Shipping_Validation()->file ), 
     95        ) ); 
     96 
    8497        // Only load scripts on relevant pages 
    8598        if ( 
     
    89102        ) : 
    90103 
    91             // Style script 
    92             wp_enqueue_style( 'woocommerce-advanced-shipping-validation-css', plugins_url( 'assets/admin/css/woocommerce-advanced-shipping-validation.css', Woocommerce_Advanced_Shipping_Validation()->file ), array(), Woocommerce_Advanced_Shipping_Validation()->version ); 
     104            wp_localize_script( 'wp-conditions', 'wpc2', array( 
     105                'action_prefix' => 'wcasv_', 
     106            ) ); 
    93107 
    94             // Javascript 
    95             wp_enqueue_script( 'woocommerce-advanced-shipping-validation-js', plugins_url( 'assets/admin/js/woocommerce-advanced-shipping-validation.min.js', Woocommerce_Advanced_Shipping_Validation()->file ), array( 'jquery', 'jquery-ui-sortable' ), Woocommerce_Advanced_Shipping_Validation()->version, true ); 
    96  
    97             wp_localize_script( 'woocommerce-advanced-shipping-validation-js', 'wpc', array( 
    98                 'nonce'         => wp_create_nonce( 'wpc-ajax-nonce' ), 
    99                 'action_prefix' => 'wcasv_', 
    100                 'asset_url'     => plugins_url( 'assets/', Woocommerce_Advanced_Shipping_Validation()->file ), 
    101             ) ); 
     108            wp_enqueue_script( 'woocommerce-advanced-shipping-validation' ); 
     109            wp_enqueue_style( 'woocommerce-advanced-shipping-validation' ); 
     110            wp_enqueue_script( 'wp-conditions' ); 
    102111 
    103112            wp_dequeue_script( 'autosave' ); 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/admin/class-wcasv-condition.php

    r1493453 r1607412  
    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; 
     
    148148     */ 
    149149    public function get_operators() { 
    150  
    151         $operators = array( 
    152             '==' => __( 'Equal to', 'woocommerce-advanced-shipping-validation' ), 
    153             '!=' => __( 'Not equal to', 'woocommerce-advanced-shipping-validation' ), 
    154             '>=' => __( 'Greater or equal to', 'woocommerce-advanced-shipping-validation' ), 
    155             '<=' => __( 'Less or equal to ', 'woocommerce-advanced-shipping-validation' ), 
    156         ); 
    157         $operators = apply_filters( 'woocommerce_Advanced_Shipping_Validation_operators', $operators ); 
    158  
    159         return $operators; 
    160  
     150        $wpc_condition = wpc_get_condition( $this->condition ); 
     151        return apply_filters( 'woocommerce_Advanced_Shipping_Validation_operators', $wpc_condition->get_available_operators() ); 
    161152    } 
    162153 
     
    175166 
    176167        // Defaults 
    177         $values = array( 
     168        $default_field_args = array( 
    178169            'name'        => 'conditions[' . absint( $this->group ) . '][' . absint( $this->id ) . '][value]', 
    179170            'placeholder' => '', 
    180171            'type'        => 'text', 
    181             'class'       => array( 'wpc-value' ) 
     172            'class'       => array( 'wpc-value' ), 
    182173        ); 
    183174 
    184         switch ( $this->condition ) : 
    185  
    186             default: 
    187             case 'subtotal' : 
    188             case 'shipping_cost' : 
    189                 $values['type'] = 'text'; 
    190                 break; 
    191  
    192             case 'shipping_method' : 
    193                 $values['type'] = 'select'; 
    194                 foreach ( WC()->shipping->load_shipping_methods() as $method ) : 
    195                     $values['options'][ $method->id ] = $method->get_title(); 
    196                 endforeach; 
    197  
    198                 // WooCommerce Advanced Shipping support 
    199                 $was_rates = get_posts( array( 'fields' => 'ids', 'post_type' => 'was', 'post_status' => 'any', 'posts_per_page' => 1000 ) ); 
    200                 foreach ( $was_rates as $was_id ) : 
    201                     $shipping_method              = get_post_meta( $was_id, '_was_shipping_method', true ); 
    202                     $values['options'][ $was_id ] = isset( $shipping_method['shipping_title'] ) ? $shipping_method['shipping_title'] : 'WooCommerce Advanced Shipping rate ID ' . $was_id; 
    203                 endforeach; 
    204                 break; 
    205  
    206             case 'payment_gateway' : 
    207                 $values['type'] = 'select'; 
    208                 foreach ( WC()->payment_gateways->payment_gateways() as $gateway ) : 
    209                     $values['options'][ $gateway->id ] = $gateway->get_title(); 
    210                 endforeach; 
    211  
    212                 break; 
    213  
    214             case 'subtotal_ex_tax' : 
    215             case 'tax' : 
    216             case 'quantity' : 
    217                 $values['type'] = 'text'; 
    218                 break; 
    219  
    220             case 'contains_product' : 
    221  
    222                 $product = wc_get_product( $this->value ); 
    223                 if ( $product ) { 
    224                     $values['custom_attributes']['data-selected'] = $product->get_formatted_name(); 
    225                 } 
    226  
    227                 $values['type']        = 'text'; 
    228                 $values['placeholder'] =  __( 'Search for a product', 'woocommerce-advanced-messages' ); 
    229                 $values['class'][]     = 'wc-product-search'; 
    230  
    231                 break; 
    232  
    233             case 'coupon' : 
    234             case 'weight' : 
    235                 $values['type'] = 'text'; 
    236                 break; 
    237  
    238             case 'contains_shipping_class' : 
    239                 $values['type']          = 'select'; 
    240                 $values['options']['-1'] = __( 'No shipping class', 'woocommerce' ); 
    241                 $values['class'][]       = 'wc-enhanced-select'; 
    242  
    243                 // Get all shipping classes 
    244                 foreach ( get_terms( 'product_shipping_class', array( 'hide_empty' => false ) ) as $shipping_class ) : 
    245                     $values['options'][ $shipping_class->slug ] = $shipping_class->name; 
    246                 endforeach; 
    247  
    248                 break; 
    249  
    250             /************************************************************** 
    251              * User details 
    252              *************************************************************/ 
    253  
    254             case 'zipcode' : 
    255             case 'city' : 
    256                 $values['type'] = 'text'; 
    257                 break; 
    258  
    259             case 'state' : 
    260                 $values['type']    = 'select'; 
    261                 $values['class'][] = 'wc-enhanced-select'; 
    262  
    263                 $country_states = array(); 
    264                 foreach ( WC()->countries->states as $country => $states ) : 
    265  
    266                     if ( empty( $states ) ) continue; // Don't show country if it has no states 
    267                     if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries 
    268  
    269                     foreach ( $states as $state_key => $state ) : 
    270                         $country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state; 
    271                     endforeach; 
    272  
    273                     $values['options'] = $country_states; 
    274  
    275                 endforeach; 
    276  
    277                 break; 
    278  
    279             case 'country' : 
    280  
    281                 $values['field']   = 'select'; 
    282                 $values['class'][] = 'wc-enhanced-select'; 
    283  
    284                 $countries  =  WC()->countries->get_allowed_countries() + WC()->countries->get_shipping_countries(); 
    285                 $continents = array(); 
    286                 if ( method_exists( WC()->countries, 'get_continents' ) ) : 
    287                     foreach ( WC()->countries->get_continents() as $k => $v ) : 
    288                         $continents[ 'CO_' . $k ] = $v['name']; // Add prefix for country key compatibility 
    289                     endforeach; 
    290                 endif; 
    291  
    292                 if ( $continents ) { 
    293                     $values['options'][ __( 'Continents', 'woocommerce' ) ] = $continents; 
    294                 } 
    295                 $values['options'][ __( 'Countries', 'woocommerce' ) ] = $countries; 
    296  
    297                 break; 
    298  
    299             case 'role' : 
    300  
    301                 $values['type']    = 'select'; 
    302                 $roles             = array_keys( get_editable_roles() ); 
    303                 $values['options'] = array_combine( $roles, $roles ); 
    304  
    305                 break; 
    306  
    307             /************************************************************** 
    308              * Product 
    309              *************************************************************/ 
    310  
    311             case 'width' : 
    312             case 'height' : 
    313             case 'length' : 
    314             case 'stock' : 
    315                 $values['type'] = 'text'; 
    316                 break; 
    317  
    318             case 'stock_status' : 
    319  
    320                 $values['type']    = 'select'; 
    321                 $values['options'] = array( 
    322                     'instock'    => __( 'In stock', 'woocommerce' ), 
    323                     'outofstock' => __( 'Out of stock', 'woocommerce' ), 
    324                 ); 
    325  
    326                 break; 
    327  
    328             case 'contains_category' : 
    329  
    330                 $values['type'] = 'select'; 
    331  
    332                 $categories = get_terms( 'product_cat', array( 'hide_empty' => false ) ); 
    333                 foreach ( $categories as $category ) : 
    334                     $values['options'][ $category->slug ] = $category->name; 
    335                 endforeach; 
    336  
    337                 break; 
    338  
    339         endswitch; 
    340  
    341         $values = apply_filters( 'woocommerce_advanced_shipping_validation_values', $values, $this->condition ); 
    342  
    343         return $values; 
     175 
     176        $field_args = $default_field_args; 
     177        if ( $condition = wpc_get_condition( $this->condition ) ) { 
     178            $field_args = wp_parse_args( $condition->get_value_field_args(), $default_field_args ); 
     179        } 
     180 
     181        if ( $this->condition == 'contains_product' && $product = wc_get_product( $this->value ) ) { 
     182            $field_args['custom_attributes']['data-selected'] = $product->get_formatted_name(); // WC < 2.7 
     183            $field_args['options'][ $this->value ] = $product->get_formatted_name(); // WC >= 2.7 
     184        } 
     185 
     186        if ( $this->condition == 'shipping_cost' ) : 
     187            $field_args['field'] = 'text'; 
     188        endif; 
     189 
     190        $field_args = apply_filters( 'woocommerce_advanced_shipping_validation_values', $field_args, $this->condition ); 
     191 
     192        return $field_args; 
    344193 
    345194    } 
     
    354203     */ 
    355204    public function get_description() { 
    356  
    357         $descriptions = array( 
    358             'shipping_cost'           => __( 'Shipping cost is based on the shipping package cost (taxes not counted)', 'woocommerce-advanced-shipping-validation' ), 
    359             'state'                   => __( 'States must be installed in WC', 'woocommerce-advanced-shipping-validation' ), 
    360             'zipcode'                 => __( 'Zipcodes can be separated by comma. Will match when user zipcode \'starts with\' any of the provided zipcodes.', 'woocommerce-advanced-shipping-validation' ), 
    361             'city'                    => __( 'City can be separated by comma. Case incentive', 'woocommerce-advanced-shipping-validation' ), 
    362             'weight'                  => __( 'Weight calculated on all the cart contents', 'woocommerce-advanced-shipping-validation' ), 
    363             'length'                  => __( 'Compared to lengthiest product in cart', 'woocommerce-advanced-shipping-validation' ), 
    364             'width'                   => __( 'Compared to widest product in cart', 'woocommerce-advanced-shipping-validation' ), 
    365             'height'                  => __( 'Compared to highest product in cart', 'woocommerce-advanced-shipping-validation' ), 
    366             'stock_status'            => __( 'All products in cart must match stock status', 'woocommerce-advanced-shipping-validation' ), 
    367             'contains_category'       => __( 'Cart must contain least one product with the selected category', 'woocommerce-advanced-shipping-validation' ), 
    368             'contains_product'        => __( 'Cart must contain one of this product', 'woocommerce-advanced-shipping-validation' ), 
    369             'contains_shipping_class' => __( 'Cart must contain at least one product with the selected shipping class', 'woocommerce-advanced-shipping-validation' ), 
    370         ); 
    371         $descriptions = apply_filters( 'woocommerce_Advanced_Shipping_Validation_descriptions', $descriptions ); 
    372  
     205        $descriptions = apply_filters( 'woocommerce_Advanced_Shipping_Validation_descriptions', wpc_condition_descriptions() ); 
    373206        return isset( $descriptions[ $this->condition ] ) ? $descriptions[ $this->condition ] : ''; 
    374  
    375207    } 
    376208 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/admin/views/html-condition-row.php

    r1485561 r1607412  
    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 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/admin/views/html-meta-box-conditions.php

    r1493453 r1607412  
    88 
    99    <p> 
    10         <strong><?php _e( 'Match all of the following rules to apply the validation rule:', 'woocommerce-advanced-shipping-validation' ); ?></strong> 
     10        <strong><?php _e( 'Match one of the condition groups to display the validation rule:', 'woocommerce-advanced-shipping-validation' ); ?></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-match'><?php _e( 'Or match all of the following rules to apply the validation rule:', 'woocommerce-advanced-shipping-validation' ); ?></p><?php 
    20  
    21             foreach ( $conditions as $condition_id => $condition ) : 
    22                 $wp_condition = new WCASV_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-shipping-validation' ); ?></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 WCASV_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-shipping-validation' ); ?></a> 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/admin/views/html-overview-table.php

    r1493453 r1607412  
    1010    <td class="forminp"> 
    1111 
    12         <table class='wp-list-table wpc-conditions-post-table widefat'> 
     12        <table class='wp-list-table wpc-conditions-post-table wpc-sortable-post-table widefat'> 
    1313            <thead> 
    1414                <tr> 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/class-wcasv-ajax.php

    r1493453 r1607412  
    2020    public function __construct() { 
    2121 
    22         // Add elements 
    23         add_action( 'wp_ajax_wcasv_add_condition', array( $this, 'add_condition' ) ); 
    24         add_action( 'wp_ajax_wcasv_add_condition_group', array( $this, 'add_condition_group' ) ); 
    25  
    2622        // Update elements 
    2723        add_action( 'wp_ajax_wcasv_update_condition_value', array( $this, 'update_condition_value' ) ); 
    28         add_action( 'wp_ajax_wcasv_update_condition_description', array( $this, 'update_condition_description' ) ); 
    29  
    30         // Save post ordering 
    31         add_action( 'wp_ajax_wcasv_save_post_order', array( $this, 'save_post_order' ) ); 
    32  
    33     } 
    34  
    35  
    36     /** 
    37      * Add condition. 
    38      * 
    39      * Output the HTML of a new condition row. 
    40      * 
    41      * @since 1.0.0 
    42      */ 
    43     public function add_condition() { 
    44  
    45         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    46  
    47         $wp_condition = new WCASV_Condition( null, $_POST['group'] ); 
    48         $wp_condition->output_condition_row(); 
    49  
    50         die(); 
    51  
    52     } 
    53  
    54  
    55     /** 
    56      * Condition group. 
    57      * 
    58      * Output the HTML of a new condition group. 
    59      * 
    60      * @since 1.0.0 
    61      */ 
    62     public function add_condition_group() { 
    63  
    64         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    65         $group = absint( $_POST['group'] ); 
    66  
    67         ?><div class='wpc-condition-group wpc-condition-group-<?php echo $group; ?>' data-group='<?php echo $group; ?>'> 
    68  
    69         <p class='or-match'><?php _e( 'Or match all of the following rules to apply the validation rule:', 'woocommerce-advanced-shipping-validation' ); ?></p><?php 
    70  
    71         $wp_condition = new WCASV_Condition( null, $group ); 
    72         $wp_condition->output_condition_row(); 
    73  
    74         ?></div> 
    75  
    76         <p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-shipping-validation' ); ?></strong></p><?php 
    77  
    78         die(); 
    7924 
    8025    } 
     
    9540        $value_field_args = $wp_condition->get_value_field_args(); 
    9641 
    97         ?><span class='wpc-value-wrap wpc-value-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
    98         wpc_html_field( $value_field_args ); 
     42        ?><span class='wpc-value-field-wrap'><?php 
     43            wpc_html_field( $value_field_args ); 
    9944        ?></span><?php 
    10045 
     
    10449 
    10550 
    106     /** 
    107      * Update description. 
    108      * 
    109      * Render the corresponding description for the condition key. 
    110      * 
    111      * @since 1.0.0 
    112      */ 
    113     public function update_condition_description() { 
    114  
    115         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    116  
    117         $condition    = sanitize_text_field( $_POST['condition'] ); 
    118         $wp_condition = new WCASV_Condition( null, null, $condition ); 
    119  
    120         if ( $desc = $wp_condition->get_description() ) { 
    121             ?><span class='wpc-description wpc-no-description <?php echo $desc; ?>-description'><?php 
    122             die(); 
    123         } 
    124  
    125         ?><span class='wpc-description <?php echo $wp_condition->condition; ?>-description'> 
    126         <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() ); ?>" /> 
    127         </span><?php 
    128  
    129         die(); 
    130  
    131     } 
    132  
    133  
    134     /** 
    135      * Save order. 
    136      * 
    137      * Save the order of the posts in the overview table. 
    138      * 
    139      * @since 1.0.0 
    140      */ 
    141     public function save_post_order() { 
    142  
    143         global $wpdb; 
    144  
    145         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    146  
    147         $args = wp_parse_args( $_POST['form'] ); 
    148  
    149         $menu_order = 0; 
    150         foreach ( $args['sort'] as $sort ) : 
    151  
    152             $wpdb->update( 
    153                 $wpdb->posts, 
    154                 array( 'menu_order' => $menu_order ), 
    155                 array( 'ID' => $sort ), 
    156                 array( '%d' ), 
    157                 array( '%d' ) 
    158             ); 
    159  
    160             $menu_order++; 
    161  
    162         endforeach; 
    163  
    164         die; 
    165  
    166     } 
    167  
    168  
    16951} 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/class-wcasv-match-conditions.php

    r1493453 r1607412  
    2222    public function __construct() { 
    2323 
    24         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_subtotal', array( $this, 'match_condition_subtotal' ), 10, 5 ); 
    2524        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_shipping_cost', array( $this, 'match_condition_shipping_cost' ), 10, 5 ); 
    2625        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_shipping_method', array( $this, 'match_condition_shipping_method' ), 10, 5 ); 
    27         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_payment_gateway', array( $this, 'match_condition_payment_gateway' ), 10, 5 ); 
    28         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_subtotal_ex_tax', array( $this, 'match_condition_subtotal_ex_tax' ), 10, 5 ); 
    29         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_tax', array( $this, 'match_condition_tax' ), 10, 5 ); 
    3026        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_quantity', array( $this, 'match_condition_quantity' ), 10, 5 ); 
    3127        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_contains_product', array( $this, 'match_condition_contains_product' ), 10, 5 ); 
    32         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_coupon', array( $this, 'match_condition_coupon' ), 10, 5 ); 
    3328        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_weight', array( $this, 'match_condition_weight' ), 10, 5 ); 
    3429        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_contains_shipping_class', array( $this, 'match_condition_contains_shipping_class' ), 10, 5 ); 
    35  
    36         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_zipcode', array( $this, 'match_condition_zipcode' ), 10, 5 ); 
    37         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_city', array( $this, 'match_condition_city' ), 10, 5 ); 
    38         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_state', array( $this, 'match_condition_state' ), 10, 5 ); 
    39         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_country', array( $this, 'match_condition_country' ), 10, 5 ); 
    40         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_role', array( $this, 'match_condition_role' ), 10, 5 ); 
    41  
    42         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_width', array( $this, 'match_condition_width' ), 10, 5 ); 
    43         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_height', array( $this, 'match_condition_height' ), 10, 5 ); 
    44         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_length', array( $this, 'match_condition_length' ), 10, 5 ); 
    45         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_stock', array( $this, 'match_condition_stock' ), 10, 5 ); 
    46         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_stock_status', array( $this, 'match_condition_stock_status' ), 10, 5 ); 
    47         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_contains_category', array( $this, 'match_condition_contains_category' ), 10, 5 ); 
    48  
    49     } 
    50  
    51  
    52     /** 
    53      * Subtotal. 
    54      * 
    55      * Match the condition value against the cart subtotal. 
    56      * 
    57      * @since 1.0.0 
    58      * 
    59      * @param  bool   $match         Current match value. 
    60      * @param  string $operator      Operator selected by the user in the condition row. 
    61      * @param  mixed  $value         Value given by the user in the condition row. 
    62      * @param  array  $package       List of shipping package details. 
    63      * @param  int    $package_index Current shipping package index. 
    64      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    65      */ 
    66     public function match_condition_subtotal( $match, $operator, $value, $package, $package_index ) { 
    67  
    68         if ( ! isset( WC()->cart ) ) : 
    69             return $match; 
    70         endif; 
    71  
    72         // Make sure its formatted correct 
    73         $value    = str_replace( ',', '.', $value ); 
    74         $subtotal = WC()->cart->subtotal; 
    75  
    76         if ( '==' == $operator ) : 
    77             $match = ( $subtotal == $value ); 
    78         elseif ( '!=' == $operator ) : 
    79             $match = ( $subtotal != $value ); 
    80         elseif ( '>=' == $operator ) : 
    81             $match = ( $subtotal >= $value ); 
    82  
    83         elseif ( '<=' == $operator ) : 
    84             $match = ( $subtotal <= $value ); 
    85         endif; 
    86  
    87         return $match; 
    8830 
    8931    } 
     
    159101 
    160102    /** 
    161      * Payment gateway. 
    162      * 
    163      * Matches if the condition value equals the selected payment gateway. 
    164      * 
    165      * @since 1.0.0 
    166      * 
    167      * @param  bool   $match         Current match value. 
    168      * @param  string $operator      Operator selected by the user in the condition row. 
    169      * @param  mixed  $value         Value given by the user in the condition row. 
    170      * @param  array  $package       List of shipping package details. 
    171      * @param  int    $package_index Current shipping package index. 
    172      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    173      */ 
    174     public function match_condition_payment_gateway( $match, $operator, $value, $package, $package_index ) { 
    175  
    176         $selected_payment_method = WC()->session->get( 'chosen_payment_method' ); 
    177  
    178         if ( '==' == $operator ) : 
    179             $match = ( $selected_payment_method == $value ); 
    180         elseif ( '!=' == $operator ) : 
    181             $match = ( $selected_payment_method != $value ); 
    182         endif; 
    183  
    184         return $match; 
    185  
    186     } 
    187  
    188  
    189     /** 
    190      * Subtotal excl. taxes. 
    191      * 
    192      * Match the condition value against the cart subtotal excl. taxes. 
    193      * 
    194      * @since 1.0.0 
    195      * 
    196      * @param  bool   $match         Current match value. 
    197      * @param  string $operator      Operator selected by the user in the condition row. 
    198      * @param  mixed  $value         Value given by the user in the condition row. 
    199      * @param  array  $package       List of shipping package details. 
    200      * @param  int    $package_index Current shipping package index. 
    201      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    202      */ 
    203     public function match_condition_subtotal_ex_tax( $match, $operator, $value, $package, $package_index ) { 
    204  
    205         if ( ! isset( WC()->cart ) ) : 
    206             return $match; 
    207         endif; 
    208  
    209         // Make sure its formatted correct 
    210         $value = str_replace( ',', '.', $value ); 
    211  
    212         if ( '==' == $operator ) : 
    213             $match = ( WC()->cart->subtotal_ex_tax == $value ); 
    214         elseif ( '!=' == $operator ) : 
    215             $match = ( WC()->cart->subtotal_ex_tax != $value ); 
    216         elseif ( '>=' == $operator ) : 
    217             $match = ( WC()->cart->subtotal_ex_tax >= $value ); 
    218         elseif ( '<=' == $operator ) : 
    219             $match = ( WC()->cart->subtotal_ex_tax <= $value ); 
    220         endif; 
    221  
    222         return $match; 
    223  
    224     } 
    225  
    226  
    227     /** 
    228      * Taxes. 
    229      * 
    230      * Match the condition value against the cart taxes. 
    231      * 
    232      * @since 1.0.0 
    233      * 
    234      * @param  bool   $match         Current match value. 
    235      * @param  string $operator      Operator selected by the user in the condition row. 
    236      * @param  mixed  $value         Value given by the user in the condition row. 
    237      * @param  array  $package       List of shipping package details. 
    238      * @param  int    $package_index Current shipping package index. 
    239      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    240      */ 
    241     public function match_condition_tax( $match, $operator, $value, $package, $package_index ) { 
    242  
    243         if ( ! isset( WC()->cart ) ) : 
    244             return $match; 
    245         endif; 
    246  
    247         $taxes = array_sum( (array) WC()->cart->taxes ); 
    248  
    249         if ( '==' == $operator ) : 
    250             $match = ( $taxes == $value ); 
    251         elseif ( '!=' == $operator ) : 
    252             $match = ( $taxes != $value ); 
    253         elseif ( '>=' == $operator ) : 
    254             $match = ( $taxes >= $value ); 
    255         elseif ( '<=' == $operator ) : 
    256             $match = ( $taxes <= $value ); 
    257         endif; 
    258  
    259         return $match; 
    260  
    261     } 
    262  
    263  
    264     /** 
    265103     * Quantity. 
    266104     * 
     
    319157    public function match_condition_contains_product( $match, $operator, $value, $package, $package_index ) { 
    320158 
    321         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
     159        if ( ! isset( WC()->cart ) ) : 
    322160            return $match; 
    323161        endif; 
     
    352190     * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    353191     */ 
    354     public function match_condition_coupon( $match, $operator, $value, $package, $package_index ) { 
    355  
    356         if ( ! isset( WC()->cart ) ) : 
    357             return $match; 
    358         endif; 
    359  
    360         $coupons = array( 'percent' => array(), 'fixed' => array() ); 
    361         foreach ( WC()->cart->get_coupons() as $coupon ) { 
    362             $type               = str_replace( '_product', '', $coupon->discount_type ); 
    363             $type               = str_replace( '_cart', '', $type ); 
    364             $coupons[ $type ][] = $coupon->coupon_amount; 
    365         } 
    366  
    367         // Match against coupon percentage 
    368         if ( strpos( $value, '%' ) !== false ) { 
    369  
    370             $percentage_value = str_replace( '%', '', $value ); 
    371             if ( '==' == $operator ) : 
    372                 $match = in_array( $percentage_value, $coupons['percent'] ); 
    373             elseif ( '!=' == $operator ) : 
    374                 $match = ! in_array( $percentage_value, $coupons['percent'] ); 
    375             elseif ( '>=' == $operator ) : 
    376                 $match = empty( $coupons['percent'] ) ? $match : ( min( $coupons['percent'] ) >= $percentage_value ); 
    377             elseif ( '<=' == $operator ) : 
    378                 $match = ! is_array( $coupons['percent'] ) ? false : ( max( $coupons['percent'] ) <= $percentage_value ); 
    379             endif; 
    380  
    381             // Match against coupon amount 
    382         } elseif( strpos( $value, '$' ) !== false ) { 
    383  
    384             $amount_value = str_replace( '$', '', $value ); 
    385             if ( '==' == $operator ) : 
    386                 $match = in_array( $amount_value, $coupons['fixed'] ); 
    387             elseif ( '!=' == $operator ) : 
    388                 $match = ! in_array( $amount_value, $coupons['fixed'] ); 
    389             elseif ( '>=' == $operator ) : 
    390                 $match = empty( $coupons['fixed'] ) ? $match : ( min( $coupons['fixed'] ) >= $amount_value ); 
    391             elseif ( '<=' == $operator ) : 
    392                 $match = ! is_array( $coupons['fixed'] ) ? $match : ( max( $coupons['fixed'] ) <= $amount_value ); 
    393             endif; 
    394  
    395             // Match coupon codes 
    396         } else { 
    397  
    398             if ( '==' == $operator ) : 
    399                 $match = ( in_array( $value, WC()->cart->applied_coupons ) ); 
    400             elseif ( '!=' == $operator ) : 
    401                 $match = ( ! in_array( $value, WC()->cart->applied_coupons ) ); 
    402             endif; 
    403  
    404         } 
    405  
    406         return $match; 
    407  
    408     } 
    409192 
    410193 
     
    501284 
    502285 
    503     /****************************************************** 
    504      * User conditions 
    505      *****************************************************/ 
    506  
    507  
    508     /** 
    509      * Zipcode. 
    510      * 
    511      * Match the condition value against the customer's shipping zipcode. 
    512      * Zipcode matches when the customer zipcode 'starts with' the given condition value. 
    513      * 
    514      * @since 1.0.0 
    515      * 
    516      * @param  bool   $match         Current match value. 
    517      * @param  string $operator      Operator selected by the user in the condition row. 
    518      * @param  mixed  $value         Value given by the user in the condition row. 
    519      * @param  array  $package       List of shipping package details. 
    520      * @param  int    $package_index Current shipping package index. 
    521      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    522      */ 
    523     public function match_condition_zipcode( $match, $operator, $value, $package, $package_index ) { 
    524  
    525         if ( ! isset( WC()->customer ) ) return $match; 
    526  
    527         $user_zipcode = $package['destination']['postcode']; 
    528         $user_zipcode = preg_replace( '/[^0-9a-zA-Z]/', '', $user_zipcode ); 
    529  
    530         // Prepare allowed values. 
    531         $zipcodes = (array) preg_split( '/,+ */', $value ); 
    532  
    533         // Remove all non- letters and numbers 
    534         foreach ( $zipcodes as $key => $zipcode ) : 
    535             $zipcodes[ $key ] = preg_replace( '/[^0-9a-zA-Z-\*]/', '', $zipcode ); 
    536         endforeach; 
    537  
    538         if ( '==' == $operator ) : 
    539  
    540             foreach ( $zipcodes as $zipcode ) : 
    541  
    542                 if ( empty( $zipcode ) ) continue; 
    543  
    544                 $parts = explode( '-', $zipcode ); 
    545                 if ( count( $parts ) > 1 ) : 
    546                     $match = ( $user_zipcode >= min( $parts ) && $user_zipcode <= max( $parts ) ); 
    547                 else : 
    548                     $match = preg_match( '/^' . preg_quote( $zipcode, '/' ) . '/i', $user_zipcode ); 
    549                 endif; 
    550  
    551                 if ( $match == true ) { 
    552                     return true; 
    553                 } 
    554  
    555             endforeach; 
    556  
    557         elseif ( '!=' == $operator ) : 
    558  
    559             // True until proven false 
    560             $match = true; 
    561  
    562             foreach ( $zipcodes as $zipcode ) : 
    563  
    564                 $parts = explode( '-', $zipcode ); 
    565                 if ( count( $parts ) > 1 ) : 
    566                     $zipcode_match = ( $user_zipcode >= min( $parts ) && $user_zipcode <= max( $parts ) ); 
    567                 else : 
    568                     $zipcode_match = preg_match( '/^' . preg_quote( $zipcode, '/' ) . '/i', $user_zipcode ); 
    569                 endif; 
    570  
    571                 if ( $zipcode_match == true ) : 
    572                     return $match = false; 
    573                 endif; 
    574  
    575             endforeach; 
    576  
    577         elseif ( '>=' == $operator ) : 
    578             $match = ( $user_zipcode >= $value ); 
    579         elseif ( '<=' == $operator ) : 
    580             $match = ( $user_zipcode <= $value ); 
    581         endif; 
    582  
    583         return $match; 
    584  
    585     } 
    586  
    587  
    588     /** 
    589      * City. 
    590      * 
    591      * Match the condition value against the users shipping city. 
    592      * 
    593      * @since 1.0.0 
    594      * 
    595      * @param  bool   $match         Current match value. 
    596      * @param  string $operator      Operator selected by the user in the condition row. 
    597      * @param  mixed  $value         Value given by the user in the condition row. 
    598      * @param  array  $package       List of shipping package details. 
    599      * @param  int    $package_index Current shipping package index. 
    600      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    601      */ 
    602     public function match_condition_city( $match, $operator, $value, $package, $package_index ) { 
    603  
    604         if ( ! isset( WC()->customer ) ) : 
    605             return $match; 
    606         endif; 
    607  
    608         $customer_city = strtolower( WC()->customer->get_shipping_city() ); 
    609         $value         = strtolower( $value ); 
    610  
    611         if ( '==' == $operator ) : 
    612  
    613             if ( preg_match( '/\, ?/', $value ) ) : 
    614                 $match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) ); 
    615             else : 
    616                 $match = ( $value == $customer_city ); 
    617             endif; 
    618  
    619         elseif ( '!=' == $operator ) : 
    620  
    621             if ( preg_match( '/\, ?/', $value ) ) : 
    622                 $match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) ); 
    623             else : 
    624                 $match = ( $value == $customer_city ); 
    625             endif; 
    626  
    627         endif; 
    628  
    629         return $match; 
    630  
    631     } 
    632  
    633  
    634     /** 
    635      * State. 
    636      * 
    637      * Match the condition value against the users shipping state 
    638      * 
    639      * @since 1.0.0 
    640      * 
    641      * @param  bool   $match         Current match value. 
    642      * @param  string $operator      Operator selected by the user in the condition row. 
    643      * @param  mixed  $value         Value given by the user in the condition row. 
    644      * @param  array  $package       List of shipping package details. 
    645      * @param  int    $package_index Current shipping package index. 
    646      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    647      */ 
    648     public function match_condition_state( $match, $operator, $value, $package, $package_index ) { 
    649  
    650         if ( ! isset( WC()->customer ) ) : 
    651             return $match; 
    652         endif; 
    653  
    654         $state = WC()->customer->get_shipping_country() . '_' . WC()->customer->get_shipping_state(); 
    655  
    656         if ( '==' == $operator ) : 
    657             $match = ( $state == $value ); 
    658         elseif ( '!=' == $operator ) : 
    659             $match = ( $state != $value ); 
    660         endif; 
    661  
    662         return $match; 
    663  
    664     } 
    665  
    666  
    667     /** 
    668      * Country. 
    669      * 
    670      * Match the condition value against the users shipping country. 
    671      * 
    672      * @since 1.0.0 
    673      * 
    674      * @param  bool   $match         Current match value. 
    675      * @param  string $operator      Operator selected by the user in the condition row. 
    676      * @param  mixed  $value         Value given by the user in the condition row. 
    677      * @param  array  $package       List of shipping package details. 
    678      * @param  int    $package_index Current shipping package index. 
    679      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    680      */ 
    681     public function match_condition_country( $match, $operator, $value, $package, $package_index ) { 
    682  
    683         if ( ! isset( WC()->customer ) ) : 
    684             return $match; 
    685         endif; 
    686  
    687         $user_country = WC()->customer->get_shipping_country(); 
    688  
    689         if ( method_exists( WC()->countries, 'get_continent_code_for_country' ) ) : 
    690             $user_continent = WC()->countries->get_continent_code_for_country( $user_country ); 
    691         endif; 
    692  
    693         if ( '==' == $operator ) : 
    694             $match = stripos( $user_country, $value ) === 0; 
    695  
    696             // Check for continents if available 
    697             if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) : 
    698                 $match = stripos( $user_continent, str_replace( 'CO_', '', $value ) ) === 0; 
    699             endif; 
    700         elseif ( '!=' == $operator ) : 
    701             $match = stripos( $user_country, $value ) === false; 
    702  
    703             // Check for continents if available 
    704             if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) : 
    705                 $match = stripos( $user_continent, str_replace( 'CO_', '', $value ) ) === false; 
    706             endif; 
    707         endif; 
    708  
    709         return $match; 
    710  
    711     } 
    712  
    713  
    714     /** 
    715      * User role. 
    716      * 
    717      * Match the condition value against the users role. 
    718      * 
    719      * @since 1.0.0 
    720      * 
    721      * @param  bool   $match         Current match value. 
    722      * @param  string $operator      Operator selected by the user in the condition row. 
    723      * @param  mixed  $value         Value given by the user in the condition row. 
    724      * @param  array  $package       List of shipping package details. 
    725      * @param  int    $package_index Current shipping package index. 
    726      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    727      */ 
    728     public function match_condition_role( $match, $operator, $value, $package, $package_index ) { 
    729  
    730         global $current_user; 
    731  
    732         if ( '==' == $operator ) : 
    733             $match = ( array_key_exists( $value, $current_user->caps ) ); 
    734         elseif ( '!=' == $operator ) : 
    735             $match = ( ! array_key_exists( $value, $current_user->caps ) ); 
    736         endif; 
    737  
    738         return $match; 
    739  
    740     } 
    741  
    742  
    743     /****************************************************** 
    744      * Product conditions 
    745      *****************************************************/ 
    746  
    747  
    748     /** 
    749      * Width. 
    750      * 
    751      * Match the condition value against the widest product in the cart. 
    752      * 
    753      * @since 1.0.0 
    754      * 
    755      * @param  bool   $match         Current match value. 
    756      * @param  string $operator      Operator selected by the user in the condition row. 
    757      * @param  mixed  $value         Value given by the user in the condition row. 
    758      * @param  array  $package       List of shipping package details. 
    759      * @param  int    $package_index Current shipping package index. 
    760      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    761      */ 
    762     public function match_condition_width( $match, $operator, $value, $package, $package_index ) { 
    763  
    764         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
    765             return $match; 
    766         endif; 
    767  
    768         foreach ( WC()->cart->cart_contents as $product ) : 
    769  
    770             if ( true == $product['data']->variation_has_width ) : 
    771                 $width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) ); 
    772             else : 
    773                 $width[] = ( get_post_meta( $product['product_id'], '_width', true ) ); 
    774             endif; 
    775  
    776         endforeach; 
    777  
    778         $max_width = max( (array) $width ); 
    779  
    780         if ( '==' == $operator ) : 
    781             $match = ( $max_width == $value ); 
    782         elseif ( '!=' == $operator ) : 
    783             $match = ( $max_width != $value ); 
    784         elseif ( '>=' == $operator ) : 
    785             $match = ( $max_width >= $value ); 
    786         elseif ( '<=' == $operator ) : 
    787             $match = ( $max_width <= $value ); 
    788         endif; 
    789  
    790         return $match; 
    791  
    792     } 
    793  
    794  
    795     /** 
    796      * Height. 
    797      * 
    798      * Match the condition value against the highest product in the cart. 
    799      * 
    800      * @since 1.0.0 
    801      * 
    802      * @param  bool   $match         Current match value. 
    803      * @param  string $operator      Operator selected by the user in the condition row. 
    804      * @param  mixed  $value         Value given by the user in the condition row. 
    805      * @param  array  $package       List of shipping package details. 
    806      * @param  int    $package_index Current shipping package index. 
    807      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    808      */ 
    809     public function match_condition_height( $match, $operator, $value, $package, $package_index ) { 
    810  
    811         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
    812             return $match; 
    813         endif; 
    814  
    815         foreach ( WC()->cart->cart_contents as $product ) : 
    816  
    817             if ( true == $product['data']->variation_has_height ) : 
    818                 $height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) ); 
    819             else : 
    820                 $height[] = ( get_post_meta( $product['product_id'], '_height', true ) ); 
    821             endif; 
    822  
    823         endforeach; 
    824  
    825         $max_height = max( $height ); 
    826  
    827         if ( '==' == $operator ) : 
    828             $match = ( $max_height == $value ); 
    829         elseif ( '!=' == $operator ) : 
    830             $match = ( $max_height != $value ); 
    831         elseif ( '>=' == $operator ) : 
    832             $match = ( $max_height >= $value ); 
    833         elseif ( '<=' == $operator ) : 
    834             $match = ( $max_height <= $value ); 
    835         endif; 
    836  
    837         return $match; 
    838  
    839     } 
    840  
    841  
    842     /** 
    843      * Length. 
    844      * 
    845      * Match the condition value against the lenghtiest product in the cart. 
    846      * 
    847      * @since 1.0.0 
    848      * 
    849      * @param  bool   $match         Current match value. 
    850      * @param  string $operator      Operator selected by the user in the condition row. 
    851      * @param  mixed  $value         Value given by the user in the condition row. 
    852      * @param  array  $package       List of shipping package details. 
    853      * @param  int    $package_index Current shipping package index. 
    854      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    855      */ 
    856     public function match_condition_length( $match, $operator, $value, $package, $package_index ) { 
    857  
    858         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
    859             return $match; 
    860         endif; 
    861  
    862         foreach ( WC()->cart->cart_contents as $product ) : 
    863  
    864             if ( true == $product['data']->variation_has_length ) : 
    865                 $length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) ); 
    866             else : 
    867                 $length[] = ( get_post_meta( $product['product_id'], '_length', true ) ); 
    868             endif; 
    869  
    870         endforeach; 
    871  
    872         $max_length = max( $length ); 
    873  
    874         if ( '==' == $operator ) : 
    875             $match = ( $max_length == $value ); 
    876         elseif ( '!=' == $operator ) : 
    877             $match = ( $max_length != $value ); 
    878         elseif ( '>=' == $operator ) : 
    879             $match = ( $max_length >= $value ); 
    880         elseif ( '<=' == $operator ) : 
    881             $match = ( $max_length <= $value ); 
    882         endif; 
    883  
    884         return $match; 
    885  
    886     } 
    887  
    888  
    889     /** 
    890      * Product stock. 
    891      * 
    892      * Match the condition value against all cart products stock. 
    893      * 
    894      * @since 1.0.0 
    895      * 
    896      * @param  bool   $match         Current match value. 
    897      * @param  string $operator      Operator selected by the user in the condition row. 
    898      * @param  mixed  $value         Value given by the user in the condition row. 
    899      * @param  array  $package       List of shipping package details. 
    900      * @param  int    $package_index Current shipping package index. 
    901      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    902      */ 
    903     public function match_condition_stock( $match, $operator, $value, $package, $package_index ) { 
    904  
    905         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
    906             return $match; 
    907         endif; 
    908  
    909         // Get all product stocks 
    910         foreach ( WC()->cart->cart_contents as $product ) : 
    911  
    912             if ( true == $product['data']->variation_has_stock ) : 
    913                 $stock[] = ( get_post_meta( $product['data']->variation_id, '_stock', true ) ); 
    914             else : 
    915                 $stock[] = ( get_post_meta( $product['product_id'], '_stock', true ) ); 
    916             endif; 
    917  
    918         endforeach; 
    919  
    920         // Get lowest value 
    921         $min_stock = min( $stock ); 
    922  
    923         if ( '==' == $operator ) : 
    924             $match = ( $min_stock == $value ); 
    925         elseif ( '!=' == $operator ) : 
    926             $match = ( $min_stock != $value ); 
    927         elseif ( '>=' == $operator ) : 
    928             $match = ( $min_stock >= $value ); 
    929         elseif ( '<=' == $operator ) : 
    930             $match = ( $min_stock <= $value ); 
    931         endif; 
    932  
    933         return $match; 
    934  
    935     } 
    936  
    937  
    938     /** 
    939      * Stock status. 
    940      * 
    941      * Match the condition value against all cart products stock statusses. 
    942      * 
    943      * @since 1.0.0 
    944      * 
    945      * @param  bool   $match         Current match value. 
    946      * @param  string $operator      Operator selected by the user in the condition row. 
    947      * @param  mixed  $value         Value given by the user in the condition row. 
    948      * @param  array  $package       List of shipping package details. 
    949      * @param  int    $package_index Current shipping package index. 
    950      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    951      */ 
    952     public function match_condition_stock_status( $match, $operator, $value, $package, $package_index ) { 
    953  
    954         if ( ! isset( WC()->cart ) ) : 
    955             return $match; 
    956         endif; 
    957  
    958         if ( '==' == $operator ) : 
    959  
    960             $match = true; 
    961             foreach ( WC()->cart->cart_contents as $product ) : 
    962                 if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value ) : 
    963                     $match = false; 
    964                 endif; 
    965             endforeach; 
    966  
    967         elseif ( '!=' == $operator ) : 
    968  
    969             $match = true; 
    970             foreach ( WC()->cart->cart_contents as $product ) : 
    971                 if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value ) : 
    972                     $match = false; 
    973                 endif; 
    974             endforeach; 
    975  
    976         endif; 
    977  
    978         return $match; 
    979  
    980     } 
    981  
    982  
    983     /** 
    984      * Contains category. 
    985      * 
    986      * Match the condition value against all the cart products category. 
    987      * With this condition, all the products in the cart must have the given class. 
    988      * 
    989      * @since 1.0.0 
    990      * 
    991      * @param  bool   $match         Current match value. 
    992      * @param  string $operator      Operator selected by the user in the condition row. 
    993      * @param  mixed  $value         Value given by the user in the condition row. 
    994      * @param  array  $package       List of shipping package details. 
    995      * @param  int    $package_index Current shipping package index. 
    996      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    997      */ 
    998     public function match_condition_contains_category( $match, $operator, $value, $package, $package_index ) { 
    999  
    1000         if ( ! isset( WC()->cart ) ) : 
    1001             return $match; 
    1002         endif; 
    1003  
    1004         if ( '==' == $operator ) : 
    1005  
    1006             foreach ( WC()->cart->cart_contents as $product ) : 
    1007  
    1008                 if ( has_term( $value, 'product_cat', $product['product_id'] ) ) : 
    1009                     return true; 
    1010                 endif; 
    1011  
    1012             endforeach; 
    1013  
    1014         elseif ( '!=' == $operator ) : 
    1015             $match = true; 
    1016  
    1017             foreach ( WC()->cart->cart_contents as $product ) : 
    1018  
    1019                 if ( has_term( $value, 'product_cat', $product['product_id'] ) ) : 
    1020                     return false; 
    1021                 endif; 
    1022  
    1023             endforeach; 
    1024  
    1025         endif; 
    1026  
    1027         return $match; 
    1028  
    1029     } 
    1030  
    1031  
    1032286} 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/class-wcasv-post-type.php

    r1493453 r1607412  
    193193        } 
    194194 
    195         // Sanitize conditions 
    196         $save_conditions = array(); 
    197         if ( isset( $_POST['conditions'] ) ) : 
    198             foreach ( $_POST['conditions'] as $key => $condition_group ) : 
    199  
    200                 foreach ( $condition_group as $condition_id => $condition_values ) : 
    201                     foreach ( $condition_values as $condition_key => $condition_value ) : 
    202  
    203                         switch ( $condition_key ) : 
    204  
    205                             case 'condition' : 
    206                                 $condition_value = sanitize_key( $condition_value ); 
    207                                 break; 
    208  
    209                             case 'operator' : 
    210                                 $condition_value = in_array( $condition_value, array( '==', '!=', '>=', '<=' ) ) ? $condition_value : '=='; 
    211                                 break; 
    212  
    213                             case 'value' : 
    214                                 if ( is_array( $condition_value ) ) : 
    215                                     $condition_value = array_map( 'sanitize_text_field', $condition_value ); 
    216                                 elseif ( is_string( $condition_value ) ) : 
    217                                     $condition_value = sanitize_text_field( $condition_value ); 
    218                                 endif; 
    219                                 break; 
    220  
    221                             default : 
    222                                 $condition_value = sanitize_text_field( $condition_value ); 
    223                                 break; 
    224  
    225                         endswitch; 
    226  
    227                         $save_conditions[ $key ][ $condition_id ][ $condition_key ] = $condition_value; 
    228  
    229                     endforeach; 
    230                 endforeach; 
    231  
    232             endforeach; 
    233         endif; 
    234  
    235         // Save conditions 
    236         update_post_meta( $post_id, '_conditions', $save_conditions ); 
     195        // Save sanitized conditions 
     196        update_post_meta( $post_id, '_conditions', wpc_sanitize_conditions( $_POST['conditions'] ) ); 
    237197 
    238198        // Save message 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/includes/wcasv-validation-functions.php

    r1493453 r1607412  
    3131        'order'          => 'ASC', 
    3232    ) ) ); 
    33     $rules      = $rule_query->get_posts(); 
     33    $rules      = $rule_query->posts; 
    3434 
    3535    return apply_filters( 'woocommerce_advanced_shipping_validation_get_validation_rules', $rules ); 
     
    9898    $validation_rules = wcasv_get_validation_posts( array( 'fields' => 'ids' ) ); 
    9999    if ( $packages = WC()->shipping->get_packages() ) : 
    100         foreach ( $packages as $i => $package ) : 
     100        foreach ( $packages as $package_index => $package ) : 
    101101            foreach ( $validation_rules as $post_id ) : 
    102102 
    103103                $condition_groups = get_post_meta( $post_id, '_conditions', true ); 
    104                 if ( wcasv_match_conditions( $condition_groups, $package, $i ) ) : 
     104                if ( wpc_match_conditions( $condition_groups, compact( 'package', 'package_index' ) ) ) : 
    105105                    $message = get_post_meta( $post_id, '_message', true ); 
    106106                    wc_add_notice( $message, 'error' ); 
     
    117117 
    118118add_action( 'woocommerce_after_checkout_validation', 'wcasv_add_checkout_validation_messages' ); 
     119 
     120 
     121 
     122/************************************************************** 
     123 * Backwards compatibility for WP Conditions 
     124 *************************************************************/ 
     125 
     126/** 
     127 * Add the filters required for backwards-compatibility for the matching functionality. 
     128 * 
     129 * @since NEWVERSION 
     130 */ 
     131function wcasv_add_bc_filter_condition_match( $match, $condition, $operator, $value, $args = array() ) { 
     132 
     133    if ( has_filter( 'woocommerce_advanced_shipping_validation_match_condition_' . $condition ) ) { 
     134        $package = isset( $args['package'] ) ? $args['package'] : array(); 
     135        $package_index = isset( $args['package_index'] ) ? $args['package_index'] : 0; 
     136        $match = apply_filters( 'woocommerce_advanced_shipping_validation_match_condition_' . $condition, $match, $operator, $value, $package, $package_index ); 
     137    } 
     138 
     139    return $match; 
     140 
     141} 
     142add_action( 'wp-conditions\condition\match', 'wcasv_add_bc_filter_condition_match', 10, 5 ); 
     143 
     144 
     145/** 
     146 * Add condition descriptions of custom conditions. 
     147 * 
     148 * @since NEWVERSION 
     149 */ 
     150function wcasv_add_bc_filter_condition_descriptions( $descriptions ) { 
     151    return apply_filters( 'woocommerce_Advanced_Shipping_Validation_descriptions', $descriptions ); 
     152} 
     153add_filter( 'wp-conditions\condition_descriptions', 'wcasv_add_bc_filter_condition_descriptions' ); 
     154 
     155 
     156/** 
     157 * Add custom field BC. 
     158 * 
     159 * @since NEWVERSION 
     160 */ 
     161function wcasv_add_bc_action_custom_fields( $type, $args ) { 
     162 
     163    if ( has_action( 'wpc_html_field_type_' . $type ) ) { 
     164        do_action( 'wpc_html_field_type_' . $args['type'], $args ); 
     165    } 
     166 
     167} 
     168add_action( 'wp-conditions\html_field_hook', 'wcasv_add_bc_action_custom_fields' ); 
  • advanced-shipping-validation-for-woocommerce/tags/1.1.0/readme.txt

    r1493453 r1607412  
    11=== Advanced Shipping Validation for WooCommerce === 
    22Contributors: sormano 
    3 Tags: woocommerce shipping, woocommerce shipping validation, woocommerce shipping validation rules, shipping rules, prevent shipping, block shipping, prohibit shipping, forbit shipping, avoid shipping, restrict shipping, stop shipping 
    4 Requires at least: 3.6 
    5 Tested up to: 4.6 
    6 Stable tag: 1.0.3 
     3Tags: woocommerce shipping, woocommerce shipping validation, woocommerce shipping validation rules, shipping rules, prevent shipping, block shipping, prohibit shipping, forbid shipping, avoid shipping, restrict shipping, stop shipping 
     4Requires at least: 4.0 
     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 
     
    3737== Changelog == 
    3838 
     39= 1.1.0 - 03-03-2017 = IMPORTANT NOTE - As of this version, the plugin requires PHP 5.3 to function 
     40 
     41* [Improvement] - Big refactor of the backend conditions 
     42* [Improvement] - Smoother User Experience with conditions 
     43    - Instant adding of conditions / condition groups 
     44    - Only show valid operator options 
     45    - Instantly show condition descriptions 
     46    - Deleting entire condition groups 
     47    - Duplicate condition groups 
     48* [Improvement] - WC 2.7 compatibility changes 
     49 
    3950= 1.0.3 - 09-09-2016 = 
    4051 
  • advanced-shipping-validation-for-woocommerce/trunk/advanced-shipping-validation-for-woocommerce.php

    r1493453 r1607412  
    44 * Plugin URI:      http://jeroensormani.com/ 
    55 * Description:     Setup shipping validation rules based on your own conditions. Show customers a specific message why they can't continue to checkout. 
    6  * Version:         1.0.3 
     6 * Version:         1.1.0 
    77 * Author:          Jeroen Sormani 
    88 * Author URI:      http://jeroensormani.com/ 
     
    3030     * @var string $version Plugin version number. 
    3131     */ 
    32     public $version = '1.0.3'; 
     32    public $version = '1.1.0'; 
    3333 
    3434 
     
    7070        endif; 
    7171 
    72         // Initialize plugin parts 
    73         $this->init(); 
    74  
    7572        do_action( 'woocommerce_advanced_shipping_validation_init' ); 
    7673 
     
    9087    public static function instance() { 
    9188 
    92         if ( is_null( self::$instance ) ) : 
     89        if ( is_null( self::$instance ) ) { 
    9390            self::$instance = new self(); 
    94         endif; 
     91        } 
    9592 
    9693        return self::$instance; 
     
    107104     */ 
    108105    public function init() { 
     106 
     107        if ( version_compare( PHP_VERSION, '5.3', 'lt' ) ) { 
     108            return add_action( 'admin_notices', array( $this, 'php_version_notice' ) ); 
     109        } 
     110 
     111        require_once plugin_dir_path( __FILE__ ) . '/libraries/wp-conditions/functions.php'; 
    109112 
    110113        /** 
     
    122125        // AJAX 
    123126        if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) : 
    124  
    125             require_once plugin_dir_path( __FILE__ ) . '/includes/admin/admin-functions.php'; 
    126  
    127             /** 
    128              * Load ajax methods 
    129              */ 
    130127            require_once plugin_dir_path( __FILE__ ) . '/includes/class-wcasv-ajax.php'; 
    131128            $this->ajax = new WCASV_Ajax(); 
    132  
    133129        endif; 
    134130 
    135131        // Admin 
    136132        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) : 
    137  
    138             require_once plugin_dir_path( __FILE__ ) . '/includes/admin/admin-functions.php'; 
    139  
    140             /** 
    141              * Admin class. 
    142              */ 
    143133            require_once plugin_dir_path( __FILE__ ) . '/includes/admin/class-wcasv-admin.php'; 
    144134            $this->admin = new WCASV_Admin(); 
    145  
    146  
    147135        endif; 
    148136 
     
    174162 
    175163 
     164    /** 
     165     * Display PHP 5.3 required notice. 
     166     * 
     167     * Display a notice when the required PHP version is not met. 
     168     * 
     169     * @since 1.0.6 
     170     */ 
     171    public function php_version_notice() { 
     172 
     173        ?><div class='updated'> 
     174            <p><?php echo sprintf( __( 'Advanced Shipping Validation 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> 
     175        </div><?php 
     176 
     177    } 
     178 
     179 
    176180} 
    177181 
     
    198202 
    199203endif; 
    200 Woocommerce_Advanced_Shipping_Validation(); 
     204Woocommerce_Advanced_Shipping_Validation()->init(); 
  • advanced-shipping-validation-for-woocommerce/trunk/assets/admin/css/woocommerce-advanced-shipping-validation.css

    r1485561 r1607412  
    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-shipping_validation .misc-pub-visibility#visibility{display:none}.wcasv-option label{display:inline-block;width:150px}.wcasv-option input{line-height:19px;width:190px}.wcasv_settings_meta_box .wcasv-description{float:none;line-height:19px}.wcasv_settings_meta_box #validation-message{max-width:75%;width:75%;vertical-align:top}.wcasv_conditions_meta_box>p:first-child+div>.or-match{display:none} 
     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"}.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-shipping_validation .misc-pub-visibility#visibility{display:none}.wcasv-option label{display:inline-block;width:150px}.wcasv-option input{line-height:19px;width:190px}.wcasv_settings_meta_box .wcasv-description{float:none;line-height:19px}.wcasv_settings_meta_box #validation-message{max-width:75%;width:75%;vertical-align:top}.wcasv_conditions_meta_box>p:first-child+div>.or-match{display:none} 
  • advanced-shipping-validation-for-woocommerce/trunk/assets/admin/css/woocommerce-advanced-shipping-validation.scss

    r1485561 r1607412  
    1 @import 'parts/wp-conditions'; 
     1@import '../../../libraries/wp-conditions/assets/css/wp-conditions'; 
    22 
    33/* Hide visibility from admin */ 
  • advanced-shipping-validation-for-woocommerce/trunk/assets/admin/js/woocommerce-advanced-shipping-validation.js

    r1485561 r1607412  
    11jQuery( function( $ ) { 
    2  
    3     /************************************************************** 
    4      * WPC - 1.0.1 
    5      *************************************************************/ 
    6  
    7         // Add condition 
    8     $( document.body ).on( 'click', '.wpc-condition-add', function() { 
    9  
    10         var $this = $( this ); 
    11         var data = { 
    12             action: wpc.action_prefix + 'add_condition', 
    13             group: $( this ).attr( 'data-group' ), 
    14             nonce: wpc.nonce 
    15         }; 
    16         var condition_group = $this.parents( '.wpc-conditions' ).find( '.wpc-condition-group-' + data.group ); 
    17  
    18         var loading_icon = '<div class="wpc-condition-wrap loading"></div>'; 
    19         condition_group.append( loading_icon ).children( ':last' ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } }); 
    20  
    21         $.post( ajaxurl, data, function( response ) { 
    22             condition_group.find( ' .wpc-condition-wrap.loading' ).first().replaceWith( function() { 
    23                 return $( response ).hide().fadeIn( 'normal' ); 
    24             }); 
    25         }); 
    26  
    27     }); 
    28  
    29     // Delete condition 
    30     $( document.body ).on( 'click', '.wpc-condition-delete', function() { 
    31  
    32         if ( $( this ).closest( '.wpc-condition-group' ).children( '.wpc-condition-wrap' ).length == 1 ) { 
    33             $( this ).closest( '.wpc-condition-group' ).fadeOut( 'normal', function() { 
    34                 $( this ).next( '.or-text' ).remove(); 
    35                 $( this ).remove(); 
    36             }); 
    37         } else { 
    38             $( this ).closest( '.wpc-condition-wrap' ).slideUp( 'fast', function() { $( this ).remove(); }); 
    39         } 
    40  
    41     }); 
    42  
    43     // Add condition group 
    44     $( document.body ).on( 'click', '.wpc-condition-group-add', function() { 
    45  
    46         var condition_group_loading = '<div class="wpc-condition-group loading"></div>'; 
    47         var conditions = $( this ).prev( '.wpc-conditions' ); 
    48         var data = { 
    49             action: wpc.action_prefix + 'add_condition_group', 
    50             group:  parseInt( $( this ).prev( '.wpc-conditions' ).find( '.wpc-condition-group' ).length ), 
    51             nonce:  wpc.nonce 
    52         }; 
    53  
    54         // Display loading icon 
    55         conditions.append( condition_group_loading ).children( ':last' ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } }); 
    56  
    57         // Insert condition group 
    58         $.post( ajaxurl, data, function( response ) { 
    59             conditions.find( '.wpc-condition-group.loading' ).first().replaceWith( function() { 
    60                 return $( response ).hide().fadeIn( 'normal' ); 
    61             }); 
    62         }); 
    63  
    64     }); 
    65  
    66     // Update condition values 
    67     $( document.body ).on( 'change', '.wpc-condition', function () { 
    68  
    69         var loading_wrap = '<span style="width: 30%; border: 1px solid transparent; display: inline-block;">&nbsp;</span>'; 
    70         var data = { 
    71             action:     wpc.action_prefix + 'update_condition_value', 
    72             id:         $( this ).attr( 'data-id' ), 
    73             group:      $( this ).attr( 'data-group' ), 
    74             condition:  $( this ).val(), 
    75             nonce:      wpc.nonce 
    76         }; 
    77         var condition_group = $( this ).parents( '.wpc-conditions' ).find( '.wpc-condition-group-' + data.group ); 
    78         var replace = '.wpc-value-wrap-' + data.id; 
    79  
    80         // Loading icon 
    81         condition_group.find( replace ).html( loading_wrap ).block({ message: null, overlayCSS: { background: '', opacity: 0.6 } }); 
    82  
    83         // Replace value field 
    84         $.post( ajaxurl, data, function( response ) { 
    85             condition_group.find( replace ).replaceWith( response ); 
    86             $( document.body ).trigger( 'wc-enhanced-select-init' ); 
    87         }); 
    88  
    89         // Update condition description 
    90         var description = { 
    91             action:     wpc.action_prefix + 'update_condition_description', 
    92             condition:  data.condition, 
    93             nonce:      wpc.nonce 
    94         }; 
    95  
    96         $.post( ajaxurl, description, function( description_response ) { 
    97             condition_group.find( replace + ' ~ .wpc-description' ).replaceWith( description_response ); 
    98             // Tooltip 
    99             $( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 200 }); 
    100         }) 
    101  
    102     }); 
    103  
    104     // Sortable 
    105     $( '.wpc-conditions-post-table tbody' ).sortable({ 
    106         items:                  'tr', 
    107         handle:                 '.sort', 
    108         cursor:                 'move', 
    109         axis:                   'y', 
    110         scrollSensitivity:      40, 
    111         forcePlaceholderSize:   true, 
    112         helper:                 'clone', 
    113         opacity:                0.65, 
    114         placeholder:            'wc-metabox-sortable-placeholder', 
    115         start:function(event,ui){ 
    116             ui.item.css( 'background-color','#f6f6f6' ); 
    117         }, 
    118         stop:function(event,ui){ 
    119             ui.item.removeAttr( 'style' ); 
    120         }, 
    121         update: function(event, ui) { 
    122  
    123             $table  = $( this ).closest( 'table' ); 
    124             $table.block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } }); 
    125             // Update fee order 
    126             var data = { 
    127                 action: wpc.action_prefix + 'save_post_order', 
    128                 form:   $( this ).closest( 'form' ).serialize(), 
    129                 nonce:  wpc.nonce 
    130             }; 
    131  
    132             $.post( ajaxurl, data, function( response ) { 
    133                 $( '.wpc-conditions-post-table tbody tr:even' ).addClass( 'alternate' ); 
    134                 $( '.wpc-conditions-post-table tbody tr:odd' ).removeClass( 'alternate' ); 
    135                 $table.unblock(); 
    136             }); 
    137         } 
    138     }); 
    139  
    1402 
    1413    // Price input validation / error handling 
  • advanced-shipping-validation-for-woocommerce/trunk/assets/admin/js/woocommerce-advanced-shipping-validation.min.js

    r1485561 r1607412  
    1 jQuery(function($){$(document.body).on("click",".wpc-condition-add",function(){var o=$(this),n={action:wpc.action_prefix+"add_condition",group:$(this).attr("data-group"),nonce:wpc.nonce},t=o.parents(".wpc-conditions").find(".wpc-condition-group-"+n.group),i='<div class="wpc-condition-wrap loading"></div>';t.append(i).children(":last").block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,n,function(o){t.find(" .wpc-condition-wrap.loading").first().replaceWith(function(){return $(o).hide().fadeIn("normal")})})}),$(document.body).on("click",".wpc-condition-delete",function(){1==$(this).closest(".wpc-condition-group").children(".wpc-condition-wrap").length?$(this).closest(".wpc-condition-group").fadeOut("normal",function(){$(this).next(".or-text").remove(),$(this).remove()}):$(this).closest(".wpc-condition-wrap").slideUp("fast",function(){$(this).remove()})}),$(document.body).on("click",".wpc-condition-group-add",function(){var o='<div class="wpc-condition-group loading"></div>',n=$(this).prev(".wpc-conditions"),t={action:wpc.action_prefix+"add_condition_group",group:parseInt($(this).prev(".wpc-conditions").find(".wpc-condition-group").length),nonce:wpc.nonce};n.append(o).children(":last").block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,t,function(o){n.find(".wpc-condition-group.loading").first().replaceWith(function(){return $(o).hide().fadeIn("normal")})})}),$(document.body).on("change",".wpc-condition",function(){var o='<span style="width: 30%; border: 1px solid transparent; display: inline-block;">&nbsp;</span>',n={action:wpc.action_prefix+"update_condition_value",id:$(this).attr("data-id"),group:$(this).attr("data-group"),condition:$(this).val(),nonce:wpc.nonce},t=$(this).parents(".wpc-conditions").find(".wpc-condition-group-"+n.group),i=".wpc-value-wrap-"+n.id;t.find(i).html(o).block({message:null,overlayCSS:{background:"",opacity:.6}}),$.post(ajaxurl,n,function(o){t.find(i).replaceWith(o),$(document.body).trigger("wc-enhanced-select-init")});var c={action:wpc.action_prefix+"update_condition_description",condition:n.condition,nonce:wpc.nonce};$.post(ajaxurl,c,function(o){t.find(i+" ~ .wpc-description").replaceWith(o),$(".tips, .help_tip, .woocommerce-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})})}),$(".wpc-conditions-post-table tbody").sortable({items:"tr",handle:".sort",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(o,n){n.item.css("background-color","#f6f6f6")},stop:function(o,n){n.item.removeAttr("style")},update:function(o,n){$table=$(this).closest("table"),$table.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var t={action:wpc.action_prefix+"save_post_order",form:$(this).closest("form").serialize(),nonce:wpc.nonce};$.post(ajaxurl,t,function(o){$(".wpc-conditions-post-table tbody tr:even").addClass("alternate"),$(".wpc-conditions-post-table tbody tr:odd").removeClass("alternate"),$table.unblock()})}}),$(document.body).on("blur",".wcasv_input_price[type=text]",function(){$(".wc_error_tip").fadeOut("100",function(){$(this).remove()})}).on("keyup change",".wcasv_input_price[type=text]",function(){var o=$(this).val(),n=new RegExp("[^-0-9%*\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),t=o.replace(n,"");o!==t?($(this).val(t),$(document.body).triggerHandler("wc_add_error_tip",[$(this),"i18n_mon_decimal_error"])):$(document.body).triggerHandler("wc_remove_error_tip",[$(this),"i18n_mon_decimal_error"])})}); 
     1jQuery(function($){$(document.body).on("blur",".wcasv_input_price[type=text]",function(){$(".wc_error_tip").fadeOut("100",function(){$(this).remove()})}).on("keyup change",".wcasv_input_price[type=text]",function(){var e=$(this).val(),r=new RegExp("[^-0-9%*\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),t=e.replace(r,"");e!==t?($(this).val(t),$(document.body).triggerHandler("wc_add_error_tip",[$(this),"i18n_mon_decimal_error"])):$(document.body).triggerHandler("wc_remove_error_tip",[$(this),"i18n_mon_decimal_error"])})}); 
  • advanced-shipping-validation-for-woocommerce/trunk/codeoversight.yml

    r1420767 r1607412  
    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 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/admin/class-wcasv-admin-settings.php

    r1493453 r1607412  
    2020     * @since 1.0.0 
    2121     */ 
    22     public function __construct() { 
    23  
    24         add_action( 'admin_init', array( $this, 'init' ), 20 ); 
    25  
    26     } 
     22    public function __construct() {} 
    2723 
    2824 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/admin/class-wcasv-admin.php

    r1485561 r1607412  
    4444        require_once plugin_dir_path( __FILE__ ) . 'class-wcasv-admin-settings.php'; 
    4545        $this->settings = new WCASV_Admin_Settings(); 
     46        $this->settings->init(); 
    4647 
    4748        global $pagenow; 
     
    8283    public function admin_enqueue_scripts() { 
    8384 
     85        // Style script 
     86        wp_register_style( 'woocommerce-advanced-shipping-validation', plugins_url( 'assets/admin/css/woocommerce-advanced-shipping-validation.css', Woocommerce_Advanced_Shipping_Validation()->file ), array(), Woocommerce_Advanced_Shipping_Validation()->version ); 
     87 
     88        // Javascript 
     89        wp_register_script( 'woocommerce-advanced-shipping-validation', plugins_url( 'assets/admin/js/woocommerce-advanced-shipping-validation.min.js', Woocommerce_Advanced_Shipping_Validation()->file ), array( 'jquery', 'jquery-ui-sortable' ), Woocommerce_Advanced_Shipping_Validation()->version, true ); 
     90 
     91        wp_localize_script( 'woocommerce-advanced-shipping-validation-js', 'wpc', array( 
     92            'nonce'         => wp_create_nonce( 'wpc-ajax-nonce' ), 
     93            'action_prefix' => 'wcasv_', 
     94            'asset_url'     => plugins_url( 'assets/', Woocommerce_Advanced_Shipping_Validation()->file ), 
     95        ) ); 
     96 
    8497        // Only load scripts on relevant pages 
    8598        if ( 
     
    89102        ) : 
    90103 
    91             // Style script 
    92             wp_enqueue_style( 'woocommerce-advanced-shipping-validation-css', plugins_url( 'assets/admin/css/woocommerce-advanced-shipping-validation.css', Woocommerce_Advanced_Shipping_Validation()->file ), array(), Woocommerce_Advanced_Shipping_Validation()->version ); 
     104            wp_localize_script( 'wp-conditions', 'wpc2', array( 
     105                'action_prefix' => 'wcasv_', 
     106            ) ); 
    93107 
    94             // Javascript 
    95             wp_enqueue_script( 'woocommerce-advanced-shipping-validation-js', plugins_url( 'assets/admin/js/woocommerce-advanced-shipping-validation.min.js', Woocommerce_Advanced_Shipping_Validation()->file ), array( 'jquery', 'jquery-ui-sortable' ), Woocommerce_Advanced_Shipping_Validation()->version, true ); 
    96  
    97             wp_localize_script( 'woocommerce-advanced-shipping-validation-js', 'wpc', array( 
    98                 'nonce'         => wp_create_nonce( 'wpc-ajax-nonce' ), 
    99                 'action_prefix' => 'wcasv_', 
    100                 'asset_url'     => plugins_url( 'assets/', Woocommerce_Advanced_Shipping_Validation()->file ), 
    101             ) ); 
     108            wp_enqueue_script( 'woocommerce-advanced-shipping-validation' ); 
     109            wp_enqueue_style( 'woocommerce-advanced-shipping-validation' ); 
     110            wp_enqueue_script( 'wp-conditions' ); 
    102111 
    103112            wp_dequeue_script( 'autosave' ); 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/admin/class-wcasv-condition.php

    r1493453 r1607412  
    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; 
     
    148148     */ 
    149149    public function get_operators() { 
    150  
    151         $operators = array( 
    152             '==' => __( 'Equal to', 'woocommerce-advanced-shipping-validation' ), 
    153             '!=' => __( 'Not equal to', 'woocommerce-advanced-shipping-validation' ), 
    154             '>=' => __( 'Greater or equal to', 'woocommerce-advanced-shipping-validation' ), 
    155             '<=' => __( 'Less or equal to ', 'woocommerce-advanced-shipping-validation' ), 
    156         ); 
    157         $operators = apply_filters( 'woocommerce_Advanced_Shipping_Validation_operators', $operators ); 
    158  
    159         return $operators; 
    160  
     150        $wpc_condition = wpc_get_condition( $this->condition ); 
     151        return apply_filters( 'woocommerce_Advanced_Shipping_Validation_operators', $wpc_condition->get_available_operators() ); 
    161152    } 
    162153 
     
    175166 
    176167        // Defaults 
    177         $values = array( 
     168        $default_field_args = array( 
    178169            'name'        => 'conditions[' . absint( $this->group ) . '][' . absint( $this->id ) . '][value]', 
    179170            'placeholder' => '', 
    180171            'type'        => 'text', 
    181             'class'       => array( 'wpc-value' ) 
     172            'class'       => array( 'wpc-value' ), 
    182173        ); 
    183174 
    184         switch ( $this->condition ) : 
    185  
    186             default: 
    187             case 'subtotal' : 
    188             case 'shipping_cost' : 
    189                 $values['type'] = 'text'; 
    190                 break; 
    191  
    192             case 'shipping_method' : 
    193                 $values['type'] = 'select'; 
    194                 foreach ( WC()->shipping->load_shipping_methods() as $method ) : 
    195                     $values['options'][ $method->id ] = $method->get_title(); 
    196                 endforeach; 
    197  
    198                 // WooCommerce Advanced Shipping support 
    199                 $was_rates = get_posts( array( 'fields' => 'ids', 'post_type' => 'was', 'post_status' => 'any', 'posts_per_page' => 1000 ) ); 
    200                 foreach ( $was_rates as $was_id ) : 
    201                     $shipping_method              = get_post_meta( $was_id, '_was_shipping_method', true ); 
    202                     $values['options'][ $was_id ] = isset( $shipping_method['shipping_title'] ) ? $shipping_method['shipping_title'] : 'WooCommerce Advanced Shipping rate ID ' . $was_id; 
    203                 endforeach; 
    204                 break; 
    205  
    206             case 'payment_gateway' : 
    207                 $values['type'] = 'select'; 
    208                 foreach ( WC()->payment_gateways->payment_gateways() as $gateway ) : 
    209                     $values['options'][ $gateway->id ] = $gateway->get_title(); 
    210                 endforeach; 
    211  
    212                 break; 
    213  
    214             case 'subtotal_ex_tax' : 
    215             case 'tax' : 
    216             case 'quantity' : 
    217                 $values['type'] = 'text'; 
    218                 break; 
    219  
    220             case 'contains_product' : 
    221  
    222                 $product = wc_get_product( $this->value ); 
    223                 if ( $product ) { 
    224                     $values['custom_attributes']['data-selected'] = $product->get_formatted_name(); 
    225                 } 
    226  
    227                 $values['type']        = 'text'; 
    228                 $values['placeholder'] =  __( 'Search for a product', 'woocommerce-advanced-messages' ); 
    229                 $values['class'][]     = 'wc-product-search'; 
    230  
    231                 break; 
    232  
    233             case 'coupon' : 
    234             case 'weight' : 
    235                 $values['type'] = 'text'; 
    236                 break; 
    237  
    238             case 'contains_shipping_class' : 
    239                 $values['type']          = 'select'; 
    240                 $values['options']['-1'] = __( 'No shipping class', 'woocommerce' ); 
    241                 $values['class'][]       = 'wc-enhanced-select'; 
    242  
    243                 // Get all shipping classes 
    244                 foreach ( get_terms( 'product_shipping_class', array( 'hide_empty' => false ) ) as $shipping_class ) : 
    245                     $values['options'][ $shipping_class->slug ] = $shipping_class->name; 
    246                 endforeach; 
    247  
    248                 break; 
    249  
    250             /************************************************************** 
    251              * User details 
    252              *************************************************************/ 
    253  
    254             case 'zipcode' : 
    255             case 'city' : 
    256                 $values['type'] = 'text'; 
    257                 break; 
    258  
    259             case 'state' : 
    260                 $values['type']    = 'select'; 
    261                 $values['class'][] = 'wc-enhanced-select'; 
    262  
    263                 $country_states = array(); 
    264                 foreach ( WC()->countries->states as $country => $states ) : 
    265  
    266                     if ( empty( $states ) ) continue; // Don't show country if it has no states 
    267                     if ( ! array_key_exists( $country, WC()->countries->get_allowed_countries() ) ) continue; // Skip unallowed countries 
    268  
    269                     foreach ( $states as $state_key => $state ) : 
    270                         $country_states[ WC()->countries->countries[ $country ] ][ $country . '_' . $state_key ] = $state; 
    271                     endforeach; 
    272  
    273                     $values['options'] = $country_states; 
    274  
    275                 endforeach; 
    276  
    277                 break; 
    278  
    279             case 'country' : 
    280  
    281                 $values['field']   = 'select'; 
    282                 $values['class'][] = 'wc-enhanced-select'; 
    283  
    284                 $countries  =  WC()->countries->get_allowed_countries() + WC()->countries->get_shipping_countries(); 
    285                 $continents = array(); 
    286                 if ( method_exists( WC()->countries, 'get_continents' ) ) : 
    287                     foreach ( WC()->countries->get_continents() as $k => $v ) : 
    288                         $continents[ 'CO_' . $k ] = $v['name']; // Add prefix for country key compatibility 
    289                     endforeach; 
    290                 endif; 
    291  
    292                 if ( $continents ) { 
    293                     $values['options'][ __( 'Continents', 'woocommerce' ) ] = $continents; 
    294                 } 
    295                 $values['options'][ __( 'Countries', 'woocommerce' ) ] = $countries; 
    296  
    297                 break; 
    298  
    299             case 'role' : 
    300  
    301                 $values['type']    = 'select'; 
    302                 $roles             = array_keys( get_editable_roles() ); 
    303                 $values['options'] = array_combine( $roles, $roles ); 
    304  
    305                 break; 
    306  
    307             /************************************************************** 
    308              * Product 
    309              *************************************************************/ 
    310  
    311             case 'width' : 
    312             case 'height' : 
    313             case 'length' : 
    314             case 'stock' : 
    315                 $values['type'] = 'text'; 
    316                 break; 
    317  
    318             case 'stock_status' : 
    319  
    320                 $values['type']    = 'select'; 
    321                 $values['options'] = array( 
    322                     'instock'    => __( 'In stock', 'woocommerce' ), 
    323                     'outofstock' => __( 'Out of stock', 'woocommerce' ), 
    324                 ); 
    325  
    326                 break; 
    327  
    328             case 'contains_category' : 
    329  
    330                 $values['type'] = 'select'; 
    331  
    332                 $categories = get_terms( 'product_cat', array( 'hide_empty' => false ) ); 
    333                 foreach ( $categories as $category ) : 
    334                     $values['options'][ $category->slug ] = $category->name; 
    335                 endforeach; 
    336  
    337                 break; 
    338  
    339         endswitch; 
    340  
    341         $values = apply_filters( 'woocommerce_advanced_shipping_validation_values', $values, $this->condition ); 
    342  
    343         return $values; 
     175 
     176        $field_args = $default_field_args; 
     177        if ( $condition = wpc_get_condition( $this->condition ) ) { 
     178            $field_args = wp_parse_args( $condition->get_value_field_args(), $default_field_args ); 
     179        } 
     180 
     181        if ( $this->condition == 'contains_product' && $product = wc_get_product( $this->value ) ) { 
     182            $field_args['custom_attributes']['data-selected'] = $product->get_formatted_name(); // WC < 2.7 
     183            $field_args['options'][ $this->value ] = $product->get_formatted_name(); // WC >= 2.7 
     184        } 
     185 
     186        if ( $this->condition == 'shipping_cost' ) : 
     187            $field_args['field'] = 'text'; 
     188        endif; 
     189 
     190        $field_args = apply_filters( 'woocommerce_advanced_shipping_validation_values', $field_args, $this->condition ); 
     191 
     192        return $field_args; 
    344193 
    345194    } 
     
    354203     */ 
    355204    public function get_description() { 
    356  
    357         $descriptions = array( 
    358             'shipping_cost'           => __( 'Shipping cost is based on the shipping package cost (taxes not counted)', 'woocommerce-advanced-shipping-validation' ), 
    359             'state'                   => __( 'States must be installed in WC', 'woocommerce-advanced-shipping-validation' ), 
    360             'zipcode'                 => __( 'Zipcodes can be separated by comma. Will match when user zipcode \'starts with\' any of the provided zipcodes.', 'woocommerce-advanced-shipping-validation' ), 
    361             'city'                    => __( 'City can be separated by comma. Case incentive', 'woocommerce-advanced-shipping-validation' ), 
    362             'weight'                  => __( 'Weight calculated on all the cart contents', 'woocommerce-advanced-shipping-validation' ), 
    363             'length'                  => __( 'Compared to lengthiest product in cart', 'woocommerce-advanced-shipping-validation' ), 
    364             'width'                   => __( 'Compared to widest product in cart', 'woocommerce-advanced-shipping-validation' ), 
    365             'height'                  => __( 'Compared to highest product in cart', 'woocommerce-advanced-shipping-validation' ), 
    366             'stock_status'            => __( 'All products in cart must match stock status', 'woocommerce-advanced-shipping-validation' ), 
    367             'contains_category'       => __( 'Cart must contain least one product with the selected category', 'woocommerce-advanced-shipping-validation' ), 
    368             'contains_product'        => __( 'Cart must contain one of this product', 'woocommerce-advanced-shipping-validation' ), 
    369             'contains_shipping_class' => __( 'Cart must contain at least one product with the selected shipping class', 'woocommerce-advanced-shipping-validation' ), 
    370         ); 
    371         $descriptions = apply_filters( 'woocommerce_Advanced_Shipping_Validation_descriptions', $descriptions ); 
    372  
     205        $descriptions = apply_filters( 'woocommerce_Advanced_Shipping_Validation_descriptions', wpc_condition_descriptions() ); 
    373206        return isset( $descriptions[ $this->condition ] ) ? $descriptions[ $this->condition ] : ''; 
    374  
    375207    } 
    376208 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/admin/views/html-condition-row.php

    r1485561 r1607412  
    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 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/admin/views/html-meta-box-conditions.php

    r1493453 r1607412  
    88 
    99    <p> 
    10         <strong><?php _e( 'Match all of the following rules to apply the validation rule:', 'woocommerce-advanced-shipping-validation' ); ?></strong> 
     10        <strong><?php _e( 'Match one of the condition groups to display the validation rule:', 'woocommerce-advanced-shipping-validation' ); ?></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-match'><?php _e( 'Or match all of the following rules to apply the validation rule:', 'woocommerce-advanced-shipping-validation' ); ?></p><?php 
    20  
    21             foreach ( $conditions as $condition_id => $condition ) : 
    22                 $wp_condition = new WCASV_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-shipping-validation' ); ?></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 WCASV_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-shipping-validation' ); ?></a> 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/admin/views/html-overview-table.php

    r1493453 r1607412  
    1010    <td class="forminp"> 
    1111 
    12         <table class='wp-list-table wpc-conditions-post-table widefat'> 
     12        <table class='wp-list-table wpc-conditions-post-table wpc-sortable-post-table widefat'> 
    1313            <thead> 
    1414                <tr> 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/class-wcasv-ajax.php

    r1493453 r1607412  
    2020    public function __construct() { 
    2121 
    22         // Add elements 
    23         add_action( 'wp_ajax_wcasv_add_condition', array( $this, 'add_condition' ) ); 
    24         add_action( 'wp_ajax_wcasv_add_condition_group', array( $this, 'add_condition_group' ) ); 
    25  
    2622        // Update elements 
    2723        add_action( 'wp_ajax_wcasv_update_condition_value', array( $this, 'update_condition_value' ) ); 
    28         add_action( 'wp_ajax_wcasv_update_condition_description', array( $this, 'update_condition_description' ) ); 
    29  
    30         // Save post ordering 
    31         add_action( 'wp_ajax_wcasv_save_post_order', array( $this, 'save_post_order' ) ); 
    32  
    33     } 
    34  
    35  
    36     /** 
    37      * Add condition. 
    38      * 
    39      * Output the HTML of a new condition row. 
    40      * 
    41      * @since 1.0.0 
    42      */ 
    43     public function add_condition() { 
    44  
    45         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    46  
    47         $wp_condition = new WCASV_Condition( null, $_POST['group'] ); 
    48         $wp_condition->output_condition_row(); 
    49  
    50         die(); 
    51  
    52     } 
    53  
    54  
    55     /** 
    56      * Condition group. 
    57      * 
    58      * Output the HTML of a new condition group. 
    59      * 
    60      * @since 1.0.0 
    61      */ 
    62     public function add_condition_group() { 
    63  
    64         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    65         $group = absint( $_POST['group'] ); 
    66  
    67         ?><div class='wpc-condition-group wpc-condition-group-<?php echo $group; ?>' data-group='<?php echo $group; ?>'> 
    68  
    69         <p class='or-match'><?php _e( 'Or match all of the following rules to apply the validation rule:', 'woocommerce-advanced-shipping-validation' ); ?></p><?php 
    70  
    71         $wp_condition = new WCASV_Condition( null, $group ); 
    72         $wp_condition->output_condition_row(); 
    73  
    74         ?></div> 
    75  
    76         <p class='or-text'><strong><?php _e( 'Or', 'woocommerce-advanced-shipping-validation' ); ?></strong></p><?php 
    77  
    78         die(); 
    7924 
    8025    } 
     
    9540        $value_field_args = $wp_condition->get_value_field_args(); 
    9641 
    97         ?><span class='wpc-value-wrap wpc-value-wrap-<?php echo absint( $wp_condition->id ); ?>'><?php 
    98         wpc_html_field( $value_field_args ); 
     42        ?><span class='wpc-value-field-wrap'><?php 
     43            wpc_html_field( $value_field_args ); 
    9944        ?></span><?php 
    10045 
     
    10449 
    10550 
    106     /** 
    107      * Update description. 
    108      * 
    109      * Render the corresponding description for the condition key. 
    110      * 
    111      * @since 1.0.0 
    112      */ 
    113     public function update_condition_description() { 
    114  
    115         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    116  
    117         $condition    = sanitize_text_field( $_POST['condition'] ); 
    118         $wp_condition = new WCASV_Condition( null, null, $condition ); 
    119  
    120         if ( $desc = $wp_condition->get_description() ) { 
    121             ?><span class='wpc-description wpc-no-description <?php echo $desc; ?>-description'><?php 
    122             die(); 
    123         } 
    124  
    125         ?><span class='wpc-description <?php echo $wp_condition->condition; ?>-description'> 
    126         <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() ); ?>" /> 
    127         </span><?php 
    128  
    129         die(); 
    130  
    131     } 
    132  
    133  
    134     /** 
    135      * Save order. 
    136      * 
    137      * Save the order of the posts in the overview table. 
    138      * 
    139      * @since 1.0.0 
    140      */ 
    141     public function save_post_order() { 
    142  
    143         global $wpdb; 
    144  
    145         check_ajax_referer( 'wpc-ajax-nonce', 'nonce' ); 
    146  
    147         $args = wp_parse_args( $_POST['form'] ); 
    148  
    149         $menu_order = 0; 
    150         foreach ( $args['sort'] as $sort ) : 
    151  
    152             $wpdb->update( 
    153                 $wpdb->posts, 
    154                 array( 'menu_order' => $menu_order ), 
    155                 array( 'ID' => $sort ), 
    156                 array( '%d' ), 
    157                 array( '%d' ) 
    158             ); 
    159  
    160             $menu_order++; 
    161  
    162         endforeach; 
    163  
    164         die; 
    165  
    166     } 
    167  
    168  
    16951} 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/class-wcasv-match-conditions.php

    r1493453 r1607412  
    2222    public function __construct() { 
    2323 
    24         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_subtotal', array( $this, 'match_condition_subtotal' ), 10, 5 ); 
    2524        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_shipping_cost', array( $this, 'match_condition_shipping_cost' ), 10, 5 ); 
    2625        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_shipping_method', array( $this, 'match_condition_shipping_method' ), 10, 5 ); 
    27         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_payment_gateway', array( $this, 'match_condition_payment_gateway' ), 10, 5 ); 
    28         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_subtotal_ex_tax', array( $this, 'match_condition_subtotal_ex_tax' ), 10, 5 ); 
    29         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_tax', array( $this, 'match_condition_tax' ), 10, 5 ); 
    3026        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_quantity', array( $this, 'match_condition_quantity' ), 10, 5 ); 
    3127        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_contains_product', array( $this, 'match_condition_contains_product' ), 10, 5 ); 
    32         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_coupon', array( $this, 'match_condition_coupon' ), 10, 5 ); 
    3328        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_weight', array( $this, 'match_condition_weight' ), 10, 5 ); 
    3429        add_filter( 'woocommerce_advanced_shipping_validation_match_condition_contains_shipping_class', array( $this, 'match_condition_contains_shipping_class' ), 10, 5 ); 
    35  
    36         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_zipcode', array( $this, 'match_condition_zipcode' ), 10, 5 ); 
    37         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_city', array( $this, 'match_condition_city' ), 10, 5 ); 
    38         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_state', array( $this, 'match_condition_state' ), 10, 5 ); 
    39         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_country', array( $this, 'match_condition_country' ), 10, 5 ); 
    40         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_role', array( $this, 'match_condition_role' ), 10, 5 ); 
    41  
    42         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_width', array( $this, 'match_condition_width' ), 10, 5 ); 
    43         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_height', array( $this, 'match_condition_height' ), 10, 5 ); 
    44         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_length', array( $this, 'match_condition_length' ), 10, 5 ); 
    45         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_stock', array( $this, 'match_condition_stock' ), 10, 5 ); 
    46         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_stock_status', array( $this, 'match_condition_stock_status' ), 10, 5 ); 
    47         add_filter( 'woocommerce_advanced_shipping_validation_match_condition_contains_category', array( $this, 'match_condition_contains_category' ), 10, 5 ); 
    48  
    49     } 
    50  
    51  
    52     /** 
    53      * Subtotal. 
    54      * 
    55      * Match the condition value against the cart subtotal. 
    56      * 
    57      * @since 1.0.0 
    58      * 
    59      * @param  bool   $match         Current match value. 
    60      * @param  string $operator      Operator selected by the user in the condition row. 
    61      * @param  mixed  $value         Value given by the user in the condition row. 
    62      * @param  array  $package       List of shipping package details. 
    63      * @param  int    $package_index Current shipping package index. 
    64      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    65      */ 
    66     public function match_condition_subtotal( $match, $operator, $value, $package, $package_index ) { 
    67  
    68         if ( ! isset( WC()->cart ) ) : 
    69             return $match; 
    70         endif; 
    71  
    72         // Make sure its formatted correct 
    73         $value    = str_replace( ',', '.', $value ); 
    74         $subtotal = WC()->cart->subtotal; 
    75  
    76         if ( '==' == $operator ) : 
    77             $match = ( $subtotal == $value ); 
    78         elseif ( '!=' == $operator ) : 
    79             $match = ( $subtotal != $value ); 
    80         elseif ( '>=' == $operator ) : 
    81             $match = ( $subtotal >= $value ); 
    82  
    83         elseif ( '<=' == $operator ) : 
    84             $match = ( $subtotal <= $value ); 
    85         endif; 
    86  
    87         return $match; 
    8830 
    8931    } 
     
    159101 
    160102    /** 
    161      * Payment gateway. 
    162      * 
    163      * Matches if the condition value equals the selected payment gateway. 
    164      * 
    165      * @since 1.0.0 
    166      * 
    167      * @param  bool   $match         Current match value. 
    168      * @param  string $operator      Operator selected by the user in the condition row. 
    169      * @param  mixed  $value         Value given by the user in the condition row. 
    170      * @param  array  $package       List of shipping package details. 
    171      * @param  int    $package_index Current shipping package index. 
    172      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    173      */ 
    174     public function match_condition_payment_gateway( $match, $operator, $value, $package, $package_index ) { 
    175  
    176         $selected_payment_method = WC()->session->get( 'chosen_payment_method' ); 
    177  
    178         if ( '==' == $operator ) : 
    179             $match = ( $selected_payment_method == $value ); 
    180         elseif ( '!=' == $operator ) : 
    181             $match = ( $selected_payment_method != $value ); 
    182         endif; 
    183  
    184         return $match; 
    185  
    186     } 
    187  
    188  
    189     /** 
    190      * Subtotal excl. taxes. 
    191      * 
    192      * Match the condition value against the cart subtotal excl. taxes. 
    193      * 
    194      * @since 1.0.0 
    195      * 
    196      * @param  bool   $match         Current match value. 
    197      * @param  string $operator      Operator selected by the user in the condition row. 
    198      * @param  mixed  $value         Value given by the user in the condition row. 
    199      * @param  array  $package       List of shipping package details. 
    200      * @param  int    $package_index Current shipping package index. 
    201      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    202      */ 
    203     public function match_condition_subtotal_ex_tax( $match, $operator, $value, $package, $package_index ) { 
    204  
    205         if ( ! isset( WC()->cart ) ) : 
    206             return $match; 
    207         endif; 
    208  
    209         // Make sure its formatted correct 
    210         $value = str_replace( ',', '.', $value ); 
    211  
    212         if ( '==' == $operator ) : 
    213             $match = ( WC()->cart->subtotal_ex_tax == $value ); 
    214         elseif ( '!=' == $operator ) : 
    215             $match = ( WC()->cart->subtotal_ex_tax != $value ); 
    216         elseif ( '>=' == $operator ) : 
    217             $match = ( WC()->cart->subtotal_ex_tax >= $value ); 
    218         elseif ( '<=' == $operator ) : 
    219             $match = ( WC()->cart->subtotal_ex_tax <= $value ); 
    220         endif; 
    221  
    222         return $match; 
    223  
    224     } 
    225  
    226  
    227     /** 
    228      * Taxes. 
    229      * 
    230      * Match the condition value against the cart taxes. 
    231      * 
    232      * @since 1.0.0 
    233      * 
    234      * @param  bool   $match         Current match value. 
    235      * @param  string $operator      Operator selected by the user in the condition row. 
    236      * @param  mixed  $value         Value given by the user in the condition row. 
    237      * @param  array  $package       List of shipping package details. 
    238      * @param  int    $package_index Current shipping package index. 
    239      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    240      */ 
    241     public function match_condition_tax( $match, $operator, $value, $package, $package_index ) { 
    242  
    243         if ( ! isset( WC()->cart ) ) : 
    244             return $match; 
    245         endif; 
    246  
    247         $taxes = array_sum( (array) WC()->cart->taxes ); 
    248  
    249         if ( '==' == $operator ) : 
    250             $match = ( $taxes == $value ); 
    251         elseif ( '!=' == $operator ) : 
    252             $match = ( $taxes != $value ); 
    253         elseif ( '>=' == $operator ) : 
    254             $match = ( $taxes >= $value ); 
    255         elseif ( '<=' == $operator ) : 
    256             $match = ( $taxes <= $value ); 
    257         endif; 
    258  
    259         return $match; 
    260  
    261     } 
    262  
    263  
    264     /** 
    265103     * Quantity. 
    266104     * 
     
    319157    public function match_condition_contains_product( $match, $operator, $value, $package, $package_index ) { 
    320158 
    321         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
     159        if ( ! isset( WC()->cart ) ) : 
    322160            return $match; 
    323161        endif; 
     
    352190     * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    353191     */ 
    354     public function match_condition_coupon( $match, $operator, $value, $package, $package_index ) { 
    355  
    356         if ( ! isset( WC()->cart ) ) : 
    357             return $match; 
    358         endif; 
    359  
    360         $coupons = array( 'percent' => array(), 'fixed' => array() ); 
    361         foreach ( WC()->cart->get_coupons() as $coupon ) { 
    362             $type               = str_replace( '_product', '', $coupon->discount_type ); 
    363             $type               = str_replace( '_cart', '', $type ); 
    364             $coupons[ $type ][] = $coupon->coupon_amount; 
    365         } 
    366  
    367         // Match against coupon percentage 
    368         if ( strpos( $value, '%' ) !== false ) { 
    369  
    370             $percentage_value = str_replace( '%', '', $value ); 
    371             if ( '==' == $operator ) : 
    372                 $match = in_array( $percentage_value, $coupons['percent'] ); 
    373             elseif ( '!=' == $operator ) : 
    374                 $match = ! in_array( $percentage_value, $coupons['percent'] ); 
    375             elseif ( '>=' == $operator ) : 
    376                 $match = empty( $coupons['percent'] ) ? $match : ( min( $coupons['percent'] ) >= $percentage_value ); 
    377             elseif ( '<=' == $operator ) : 
    378                 $match = ! is_array( $coupons['percent'] ) ? false : ( max( $coupons['percent'] ) <= $percentage_value ); 
    379             endif; 
    380  
    381             // Match against coupon amount 
    382         } elseif( strpos( $value, '$' ) !== false ) { 
    383  
    384             $amount_value = str_replace( '$', '', $value ); 
    385             if ( '==' == $operator ) : 
    386                 $match = in_array( $amount_value, $coupons['fixed'] ); 
    387             elseif ( '!=' == $operator ) : 
    388                 $match = ! in_array( $amount_value, $coupons['fixed'] ); 
    389             elseif ( '>=' == $operator ) : 
    390                 $match = empty( $coupons['fixed'] ) ? $match : ( min( $coupons['fixed'] ) >= $amount_value ); 
    391             elseif ( '<=' == $operator ) : 
    392                 $match = ! is_array( $coupons['fixed'] ) ? $match : ( max( $coupons['fixed'] ) <= $amount_value ); 
    393             endif; 
    394  
    395             // Match coupon codes 
    396         } else { 
    397  
    398             if ( '==' == $operator ) : 
    399                 $match = ( in_array( $value, WC()->cart->applied_coupons ) ); 
    400             elseif ( '!=' == $operator ) : 
    401                 $match = ( ! in_array( $value, WC()->cart->applied_coupons ) ); 
    402             endif; 
    403  
    404         } 
    405  
    406         return $match; 
    407  
    408     } 
    409192 
    410193 
     
    501284 
    502285 
    503     /****************************************************** 
    504      * User conditions 
    505      *****************************************************/ 
    506  
    507  
    508     /** 
    509      * Zipcode. 
    510      * 
    511      * Match the condition value against the customer's shipping zipcode. 
    512      * Zipcode matches when the customer zipcode 'starts with' the given condition value. 
    513      * 
    514      * @since 1.0.0 
    515      * 
    516      * @param  bool   $match         Current match value. 
    517      * @param  string $operator      Operator selected by the user in the condition row. 
    518      * @param  mixed  $value         Value given by the user in the condition row. 
    519      * @param  array  $package       List of shipping package details. 
    520      * @param  int    $package_index Current shipping package index. 
    521      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    522      */ 
    523     public function match_condition_zipcode( $match, $operator, $value, $package, $package_index ) { 
    524  
    525         if ( ! isset( WC()->customer ) ) return $match; 
    526  
    527         $user_zipcode = $package['destination']['postcode']; 
    528         $user_zipcode = preg_replace( '/[^0-9a-zA-Z]/', '', $user_zipcode ); 
    529  
    530         // Prepare allowed values. 
    531         $zipcodes = (array) preg_split( '/,+ */', $value ); 
    532  
    533         // Remove all non- letters and numbers 
    534         foreach ( $zipcodes as $key => $zipcode ) : 
    535             $zipcodes[ $key ] = preg_replace( '/[^0-9a-zA-Z-\*]/', '', $zipcode ); 
    536         endforeach; 
    537  
    538         if ( '==' == $operator ) : 
    539  
    540             foreach ( $zipcodes as $zipcode ) : 
    541  
    542                 if ( empty( $zipcode ) ) continue; 
    543  
    544                 $parts = explode( '-', $zipcode ); 
    545                 if ( count( $parts ) > 1 ) : 
    546                     $match = ( $user_zipcode >= min( $parts ) && $user_zipcode <= max( $parts ) ); 
    547                 else : 
    548                     $match = preg_match( '/^' . preg_quote( $zipcode, '/' ) . '/i', $user_zipcode ); 
    549                 endif; 
    550  
    551                 if ( $match == true ) { 
    552                     return true; 
    553                 } 
    554  
    555             endforeach; 
    556  
    557         elseif ( '!=' == $operator ) : 
    558  
    559             // True until proven false 
    560             $match = true; 
    561  
    562             foreach ( $zipcodes as $zipcode ) : 
    563  
    564                 $parts = explode( '-', $zipcode ); 
    565                 if ( count( $parts ) > 1 ) : 
    566                     $zipcode_match = ( $user_zipcode >= min( $parts ) && $user_zipcode <= max( $parts ) ); 
    567                 else : 
    568                     $zipcode_match = preg_match( '/^' . preg_quote( $zipcode, '/' ) . '/i', $user_zipcode ); 
    569                 endif; 
    570  
    571                 if ( $zipcode_match == true ) : 
    572                     return $match = false; 
    573                 endif; 
    574  
    575             endforeach; 
    576  
    577         elseif ( '>=' == $operator ) : 
    578             $match = ( $user_zipcode >= $value ); 
    579         elseif ( '<=' == $operator ) : 
    580             $match = ( $user_zipcode <= $value ); 
    581         endif; 
    582  
    583         return $match; 
    584  
    585     } 
    586  
    587  
    588     /** 
    589      * City. 
    590      * 
    591      * Match the condition value against the users shipping city. 
    592      * 
    593      * @since 1.0.0 
    594      * 
    595      * @param  bool   $match         Current match value. 
    596      * @param  string $operator      Operator selected by the user in the condition row. 
    597      * @param  mixed  $value         Value given by the user in the condition row. 
    598      * @param  array  $package       List of shipping package details. 
    599      * @param  int    $package_index Current shipping package index. 
    600      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    601      */ 
    602     public function match_condition_city( $match, $operator, $value, $package, $package_index ) { 
    603  
    604         if ( ! isset( WC()->customer ) ) : 
    605             return $match; 
    606         endif; 
    607  
    608         $customer_city = strtolower( WC()->customer->get_shipping_city() ); 
    609         $value         = strtolower( $value ); 
    610  
    611         if ( '==' == $operator ) : 
    612  
    613             if ( preg_match( '/\, ?/', $value ) ) : 
    614                 $match = ( in_array( $customer_city, preg_split( '/\, ?/', $value ) ) ); 
    615             else : 
    616                 $match = ( $value == $customer_city ); 
    617             endif; 
    618  
    619         elseif ( '!=' == $operator ) : 
    620  
    621             if ( preg_match( '/\, ?/', $value ) ) : 
    622                 $match = ( ! in_array( $customer_city, preg_split( '/\, ?/', $value ) ) ); 
    623             else : 
    624                 $match = ( $value == $customer_city ); 
    625             endif; 
    626  
    627         endif; 
    628  
    629         return $match; 
    630  
    631     } 
    632  
    633  
    634     /** 
    635      * State. 
    636      * 
    637      * Match the condition value against the users shipping state 
    638      * 
    639      * @since 1.0.0 
    640      * 
    641      * @param  bool   $match         Current match value. 
    642      * @param  string $operator      Operator selected by the user in the condition row. 
    643      * @param  mixed  $value         Value given by the user in the condition row. 
    644      * @param  array  $package       List of shipping package details. 
    645      * @param  int    $package_index Current shipping package index. 
    646      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    647      */ 
    648     public function match_condition_state( $match, $operator, $value, $package, $package_index ) { 
    649  
    650         if ( ! isset( WC()->customer ) ) : 
    651             return $match; 
    652         endif; 
    653  
    654         $state = WC()->customer->get_shipping_country() . '_' . WC()->customer->get_shipping_state(); 
    655  
    656         if ( '==' == $operator ) : 
    657             $match = ( $state == $value ); 
    658         elseif ( '!=' == $operator ) : 
    659             $match = ( $state != $value ); 
    660         endif; 
    661  
    662         return $match; 
    663  
    664     } 
    665  
    666  
    667     /** 
    668      * Country. 
    669      * 
    670      * Match the condition value against the users shipping country. 
    671      * 
    672      * @since 1.0.0 
    673      * 
    674      * @param  bool   $match         Current match value. 
    675      * @param  string $operator      Operator selected by the user in the condition row. 
    676      * @param  mixed  $value         Value given by the user in the condition row. 
    677      * @param  array  $package       List of shipping package details. 
    678      * @param  int    $package_index Current shipping package index. 
    679      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    680      */ 
    681     public function match_condition_country( $match, $operator, $value, $package, $package_index ) { 
    682  
    683         if ( ! isset( WC()->customer ) ) : 
    684             return $match; 
    685         endif; 
    686  
    687         $user_country = WC()->customer->get_shipping_country(); 
    688  
    689         if ( method_exists( WC()->countries, 'get_continent_code_for_country' ) ) : 
    690             $user_continent = WC()->countries->get_continent_code_for_country( $user_country ); 
    691         endif; 
    692  
    693         if ( '==' == $operator ) : 
    694             $match = stripos( $user_country, $value ) === 0; 
    695  
    696             // Check for continents if available 
    697             if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) : 
    698                 $match = stripos( $user_continent, str_replace( 'CO_', '', $value ) ) === 0; 
    699             endif; 
    700         elseif ( '!=' == $operator ) : 
    701             $match = stripos( $user_country, $value ) === false; 
    702  
    703             // Check for continents if available 
    704             if ( ! $match && isset( $user_continent ) && strpos( $value, 'CO_' ) === 0 ) : 
    705                 $match = stripos( $user_continent, str_replace( 'CO_', '', $value ) ) === false; 
    706             endif; 
    707         endif; 
    708  
    709         return $match; 
    710  
    711     } 
    712  
    713  
    714     /** 
    715      * User role. 
    716      * 
    717      * Match the condition value against the users role. 
    718      * 
    719      * @since 1.0.0 
    720      * 
    721      * @param  bool   $match         Current match value. 
    722      * @param  string $operator      Operator selected by the user in the condition row. 
    723      * @param  mixed  $value         Value given by the user in the condition row. 
    724      * @param  array  $package       List of shipping package details. 
    725      * @param  int    $package_index Current shipping package index. 
    726      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    727      */ 
    728     public function match_condition_role( $match, $operator, $value, $package, $package_index ) { 
    729  
    730         global $current_user; 
    731  
    732         if ( '==' == $operator ) : 
    733             $match = ( array_key_exists( $value, $current_user->caps ) ); 
    734         elseif ( '!=' == $operator ) : 
    735             $match = ( ! array_key_exists( $value, $current_user->caps ) ); 
    736         endif; 
    737  
    738         return $match; 
    739  
    740     } 
    741  
    742  
    743     /****************************************************** 
    744      * Product conditions 
    745      *****************************************************/ 
    746  
    747  
    748     /** 
    749      * Width. 
    750      * 
    751      * Match the condition value against the widest product in the cart. 
    752      * 
    753      * @since 1.0.0 
    754      * 
    755      * @param  bool   $match         Current match value. 
    756      * @param  string $operator      Operator selected by the user in the condition row. 
    757      * @param  mixed  $value         Value given by the user in the condition row. 
    758      * @param  array  $package       List of shipping package details. 
    759      * @param  int    $package_index Current shipping package index. 
    760      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    761      */ 
    762     public function match_condition_width( $match, $operator, $value, $package, $package_index ) { 
    763  
    764         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
    765             return $match; 
    766         endif; 
    767  
    768         foreach ( WC()->cart->cart_contents as $product ) : 
    769  
    770             if ( true == $product['data']->variation_has_width ) : 
    771                 $width[] = ( get_post_meta( $product['data']->variation_id, '_width', true ) ); 
    772             else : 
    773                 $width[] = ( get_post_meta( $product['product_id'], '_width', true ) ); 
    774             endif; 
    775  
    776         endforeach; 
    777  
    778         $max_width = max( (array) $width ); 
    779  
    780         if ( '==' == $operator ) : 
    781             $match = ( $max_width == $value ); 
    782         elseif ( '!=' == $operator ) : 
    783             $match = ( $max_width != $value ); 
    784         elseif ( '>=' == $operator ) : 
    785             $match = ( $max_width >= $value ); 
    786         elseif ( '<=' == $operator ) : 
    787             $match = ( $max_width <= $value ); 
    788         endif; 
    789  
    790         return $match; 
    791  
    792     } 
    793  
    794  
    795     /** 
    796      * Height. 
    797      * 
    798      * Match the condition value against the highest product in the cart. 
    799      * 
    800      * @since 1.0.0 
    801      * 
    802      * @param  bool   $match         Current match value. 
    803      * @param  string $operator      Operator selected by the user in the condition row. 
    804      * @param  mixed  $value         Value given by the user in the condition row. 
    805      * @param  array  $package       List of shipping package details. 
    806      * @param  int    $package_index Current shipping package index. 
    807      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    808      */ 
    809     public function match_condition_height( $match, $operator, $value, $package, $package_index ) { 
    810  
    811         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
    812             return $match; 
    813         endif; 
    814  
    815         foreach ( WC()->cart->cart_contents as $product ) : 
    816  
    817             if ( true == $product['data']->variation_has_height ) : 
    818                 $height[] = ( get_post_meta( $product['data']->variation_id, '_height', true ) ); 
    819             else : 
    820                 $height[] = ( get_post_meta( $product['product_id'], '_height', true ) ); 
    821             endif; 
    822  
    823         endforeach; 
    824  
    825         $max_height = max( $height ); 
    826  
    827         if ( '==' == $operator ) : 
    828             $match = ( $max_height == $value ); 
    829         elseif ( '!=' == $operator ) : 
    830             $match = ( $max_height != $value ); 
    831         elseif ( '>=' == $operator ) : 
    832             $match = ( $max_height >= $value ); 
    833         elseif ( '<=' == $operator ) : 
    834             $match = ( $max_height <= $value ); 
    835         endif; 
    836  
    837         return $match; 
    838  
    839     } 
    840  
    841  
    842     /** 
    843      * Length. 
    844      * 
    845      * Match the condition value against the lenghtiest product in the cart. 
    846      * 
    847      * @since 1.0.0 
    848      * 
    849      * @param  bool   $match         Current match value. 
    850      * @param  string $operator      Operator selected by the user in the condition row. 
    851      * @param  mixed  $value         Value given by the user in the condition row. 
    852      * @param  array  $package       List of shipping package details. 
    853      * @param  int    $package_index Current shipping package index. 
    854      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    855      */ 
    856     public function match_condition_length( $match, $operator, $value, $package, $package_index ) { 
    857  
    858         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
    859             return $match; 
    860         endif; 
    861  
    862         foreach ( WC()->cart->cart_contents as $product ) : 
    863  
    864             if ( true == $product['data']->variation_has_length ) : 
    865                 $length[] = ( get_post_meta( $product['data']->variation_id, '_length', true ) ); 
    866             else : 
    867                 $length[] = ( get_post_meta( $product['product_id'], '_length', true ) ); 
    868             endif; 
    869  
    870         endforeach; 
    871  
    872         $max_length = max( $length ); 
    873  
    874         if ( '==' == $operator ) : 
    875             $match = ( $max_length == $value ); 
    876         elseif ( '!=' == $operator ) : 
    877             $match = ( $max_length != $value ); 
    878         elseif ( '>=' == $operator ) : 
    879             $match = ( $max_length >= $value ); 
    880         elseif ( '<=' == $operator ) : 
    881             $match = ( $max_length <= $value ); 
    882         endif; 
    883  
    884         return $match; 
    885  
    886     } 
    887  
    888  
    889     /** 
    890      * Product stock. 
    891      * 
    892      * Match the condition value against all cart products stock. 
    893      * 
    894      * @since 1.0.0 
    895      * 
    896      * @param  bool   $match         Current match value. 
    897      * @param  string $operator      Operator selected by the user in the condition row. 
    898      * @param  mixed  $value         Value given by the user in the condition row. 
    899      * @param  array  $package       List of shipping package details. 
    900      * @param  int    $package_index Current shipping package index. 
    901      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    902      */ 
    903     public function match_condition_stock( $match, $operator, $value, $package, $package_index ) { 
    904  
    905         if ( ! isset( WC()->cart ) || empty( WC()->cart->cart_contents ) ) : 
    906             return $match; 
    907         endif; 
    908  
    909         // Get all product stocks 
    910         foreach ( WC()->cart->cart_contents as $product ) : 
    911  
    912             if ( true == $product['data']->variation_has_stock ) : 
    913                 $stock[] = ( get_post_meta( $product['data']->variation_id, '_stock', true ) ); 
    914             else : 
    915                 $stock[] = ( get_post_meta( $product['product_id'], '_stock', true ) ); 
    916             endif; 
    917  
    918         endforeach; 
    919  
    920         // Get lowest value 
    921         $min_stock = min( $stock ); 
    922  
    923         if ( '==' == $operator ) : 
    924             $match = ( $min_stock == $value ); 
    925         elseif ( '!=' == $operator ) : 
    926             $match = ( $min_stock != $value ); 
    927         elseif ( '>=' == $operator ) : 
    928             $match = ( $min_stock >= $value ); 
    929         elseif ( '<=' == $operator ) : 
    930             $match = ( $min_stock <= $value ); 
    931         endif; 
    932  
    933         return $match; 
    934  
    935     } 
    936  
    937  
    938     /** 
    939      * Stock status. 
    940      * 
    941      * Match the condition value against all cart products stock statusses. 
    942      * 
    943      * @since 1.0.0 
    944      * 
    945      * @param  bool   $match         Current match value. 
    946      * @param  string $operator      Operator selected by the user in the condition row. 
    947      * @param  mixed  $value         Value given by the user in the condition row. 
    948      * @param  array  $package       List of shipping package details. 
    949      * @param  int    $package_index Current shipping package index. 
    950      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    951      */ 
    952     public function match_condition_stock_status( $match, $operator, $value, $package, $package_index ) { 
    953  
    954         if ( ! isset( WC()->cart ) ) : 
    955             return $match; 
    956         endif; 
    957  
    958         if ( '==' == $operator ) : 
    959  
    960             $match = true; 
    961             foreach ( WC()->cart->cart_contents as $product ) : 
    962                 if ( get_post_meta( $product['product_id'], '_stock_status', true ) != $value ) : 
    963                     $match = false; 
    964                 endif; 
    965             endforeach; 
    966  
    967         elseif ( '!=' == $operator ) : 
    968  
    969             $match = true; 
    970             foreach ( WC()->cart->cart_contents as $product ) : 
    971                 if ( get_post_meta( $product['product_id'], '_stock_status', true ) == $value ) : 
    972                     $match = false; 
    973                 endif; 
    974             endforeach; 
    975  
    976         endif; 
    977  
    978         return $match; 
    979  
    980     } 
    981  
    982  
    983     /** 
    984      * Contains category. 
    985      * 
    986      * Match the condition value against all the cart products category. 
    987      * With this condition, all the products in the cart must have the given class. 
    988      * 
    989      * @since 1.0.0 
    990      * 
    991      * @param  bool   $match         Current match value. 
    992      * @param  string $operator      Operator selected by the user in the condition row. 
    993      * @param  mixed  $value         Value given by the user in the condition row. 
    994      * @param  array  $package       List of shipping package details. 
    995      * @param  int    $package_index Current shipping package index. 
    996      * @return BOOL                  Matching result, TRUE if results match, otherwise FALSE. 
    997      */ 
    998     public function match_condition_contains_category( $match, $operator, $value, $package, $package_index ) { 
    999  
    1000         if ( ! isset( WC()->cart ) ) : 
    1001             return $match; 
    1002         endif; 
    1003  
    1004         if ( '==' == $operator ) : 
    1005  
    1006             foreach ( WC()->cart->cart_contents as $product ) : 
    1007  
    1008                 if ( has_term( $value, 'product_cat', $product['product_id'] ) ) : 
    1009                     return true; 
    1010                 endif; 
    1011  
    1012             endforeach; 
    1013  
    1014         elseif ( '!=' == $operator ) : 
    1015             $match = true; 
    1016  
    1017             foreach ( WC()->cart->cart_contents as $product ) : 
    1018  
    1019                 if ( has_term( $value, 'product_cat', $product['product_id'] ) ) : 
    1020                     return false; 
    1021                 endif; 
    1022  
    1023             endforeach; 
    1024  
    1025         endif; 
    1026  
    1027         return $match; 
    1028  
    1029     } 
    1030  
    1031  
    1032286} 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/class-wcasv-post-type.php

    r1493453 r1607412  
    193193        } 
    194194 
    195         // Sanitize conditions 
    196         $save_conditions = array(); 
    197         if ( isset( $_POST['conditions'] ) ) : 
    198             foreach ( $_POST['conditions'] as $key => $condition_group ) : 
    199  
    200                 foreach ( $condition_group as $condition_id => $condition_values ) : 
    201                     foreach ( $condition_values as $condition_key => $condition_value ) : 
    202  
    203                         switch ( $condition_key ) : 
    204  
    205                             case 'condition' : 
    206                                 $condition_value = sanitize_key( $condition_value ); 
    207                                 break; 
    208  
    209                             case 'operator' : 
    210                                 $condition_value = in_array( $condition_value, array( '==', '!=', '>=', '<=' ) ) ? $condition_value : '=='; 
    211                                 break; 
    212  
    213                             case 'value' : 
    214                                 if ( is_array( $condition_value ) ) : 
    215                                     $condition_value = array_map( 'sanitize_text_field', $condition_value ); 
    216                                 elseif ( is_string( $condition_value ) ) : 
    217                                     $condition_value = sanitize_text_field( $condition_value ); 
    218                                 endif; 
    219                                 break; 
    220  
    221                             default : 
    222                                 $condition_value = sanitize_text_field( $condition_value ); 
    223                                 break; 
    224  
    225                         endswitch; 
    226  
    227                         $save_conditions[ $key ][ $condition_id ][ $condition_key ] = $condition_value; 
    228  
    229                     endforeach; 
    230                 endforeach; 
    231  
    232             endforeach; 
    233         endif; 
    234  
    235         // Save conditions 
    236         update_post_meta( $post_id, '_conditions', $save_conditions ); 
     195        // Save sanitized conditions 
     196        update_post_meta( $post_id, '_conditions', wpc_sanitize_conditions( $_POST['conditions'] ) ); 
    237197 
    238198        // Save message 
  • advanced-shipping-validation-for-woocommerce/trunk/includes/wcasv-validation-functions.php

    r1493453 r1607412  
    3131        'order'          => 'ASC', 
    3232    ) ) ); 
    33     $rules      = $rule_query->get_posts(); 
     33    $rules      = $rule_query->posts; 
    3434 
    3535    return apply_filters( 'woocommerce_advanced_shipping_validation_get_validation_rules', $rules ); 
     
    9898    $validation_rules = wcasv_get_validation_posts( array( 'fields' => 'ids' ) ); 
    9999    if ( $packages = WC()->shipping->get_packages() ) : 
    100         foreach ( $packages as $i => $package ) : 
     100        foreach ( $packages as $package_index => $package ) : 
    101101            foreach ( $validation_rules as $post_id ) : 
    102102 
    103103                $condition_groups = get_post_meta( $post_id, '_conditions', true ); 
    104                 if ( wcasv_match_conditions( $condition_groups, $package, $i ) ) : 
     104                if ( wpc_match_conditions( $condition_groups, compact( 'package', 'package_index' ) ) ) : 
    105105                    $message = get_post_meta( $post_id, '_message', true ); 
    106106                    wc_add_notice( $message, 'error' ); 
     
    117117 
    118118add_action( 'woocommerce_after_checkout_validation', 'wcasv_add_checkout_validation_messages' ); 
     119 
     120 
     121 
     122/************************************************************** 
     123 * Backwards compatibility for WP Conditions 
     124 *************************************************************/ 
     125 
     126/** 
     127 * Add the filters required for backwards-compatibility for the matching functionality. 
     128 * 
     129 * @since NEWVERSION 
     130 */ 
     131function wcasv_add_bc_filter_condition_match( $match, $condition, $operator, $value, $args = array() ) { 
     132 
     133    if ( has_filter( 'woocommerce_advanced_shipping_validation_match_condition_' . $condition ) ) { 
     134        $package = isset( $args['package'] ) ? $args['package'] : array(); 
     135        $package_index = isset( $args['package_index'] ) ? $args['package_index'] : 0; 
     136        $match = apply_filters( 'woocommerce_advanced_shipping_validation_match_condition_' . $condition, $match, $operator, $value, $package, $package_index ); 
     137    } 
     138 
     139    return $match; 
     140 
     141} 
     142add_action( 'wp-conditions\condition\match', 'wcasv_add_bc_filter_condition_match', 10, 5 ); 
     143 
     144 
     145/** 
     146 * Add condition descriptions of custom conditions. 
     147 * 
     148 * @since NEWVERSION 
     149 */ 
     150function wcasv_add_bc_filter_condition_descriptions( $descriptions ) { 
     151    return apply_filters( 'woocommerce_Advanced_Shipping_Validation_descriptions', $descriptions ); 
     152} 
     153add_filter( 'wp-conditions\condition_descriptions', 'wcasv_add_bc_filter_condition_descriptions' ); 
     154 
     155 
     156/** 
     157 * Add custom field BC. 
     158 * 
     159 * @since NEWVERSION 
     160 */ 
     161function wcasv_add_bc_action_custom_fields( $type, $args ) { 
     162 
     163    if ( has_action( 'wpc_html_field_type_' . $type ) ) { 
     164        do_action( 'wpc_html_field_type_' . $args['type'], $args ); 
     165    } 
     166 
     167} 
     168add_action( 'wp-conditions\html_field_hook', 'wcasv_add_bc_action_custom_fields' ); 
  • advanced-shipping-validation-for-woocommerce/trunk/readme.txt

    r1493453 r1607412  
    11=== Advanced Shipping Validation for WooCommerce === 
    22Contributors: sormano 
    3 Tags: woocommerce shipping, woocommerce shipping validation, woocommerce shipping validation rules, shipping rules, prevent shipping, block shipping, prohibit shipping, forbit shipping, avoid shipping, restrict shipping, stop shipping 
    4 Requires at least: 3.6 
    5 Tested up to: 4.6 
    6 Stable tag: 1.0.3 
     3Tags: woocommerce shipping, woocommerce shipping validation, woocommerce shipping validation rules, shipping rules, prevent shipping, block shipping, prohibit shipping, forbid shipping, avoid shipping, restrict shipping, stop shipping 
     4Requires at least: 4.0 
     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 
     
    3737== Changelog == 
    3838 
     39= 1.1.0 - 03-03-2017 = IMPORTANT NOTE - As of this version, the plugin requires PHP 5.3 to function 
     40 
     41* [Improvement] - Big refactor of the backend conditions 
     42* [Improvement] - Smoother User Experience with conditions 
     43    - Instant adding of conditions / condition groups 
     44    - Only show valid operator options 
     45    - Instantly show condition descriptions 
     46    - Deleting entire condition groups 
     47    - Duplicate condition groups 
     48* [Improvement] - WC 2.7 compatibility changes 
     49 
    3950= 1.0.3 - 09-09-2016 = 
    4051 
Note: See TracChangeset for help on using the changeset viewer.