rightpress-conditions.class.php 27.2 KB
Newer Older
Pham Huy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
<?php

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}

/**
 * RightPress Conditions Helper
 */
if (!class_exists('RightPress_Conditions')) {

final class RightPress_Conditions
{

    /**
     * Get all hierarchical taxonomy terms
     *
     * @access public
     * @param string $taxonomy
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_hierarchical_taxonomy_terms($taxonomy, $ids = array(), $query = '')
    {
        $items = array();

        // Get terms
        $terms = get_terms(array($taxonomy), array('hide_empty' => 0));
        $term_count = count($terms);

        // Iterate over terms
        foreach ($terms as $term_key => $term) {

            // Get term name
            $term_name = $term->name;

            // Term has parent
            if ($term->parent) {

                $parent_id = $term->parent;
                $has_parent = true;

                // Make sure we don't have an infinite loop here (happens with some kind of "ghost" terms)
                $found = false;
                $i = 0;

                while ($has_parent && ($i < $term_count || $found)) {

                    // Reset each time
                    $found = false;
                    $i = 0;

                    // Iterate over terms again
                    foreach ($terms as $parent_term_key => $parent_term) {

                        $i++;

                        if ($parent_term->term_id == $parent_id) {

                            $term_name = $parent_term->name . ' → ' . $term_name;
                            $found = true;

                            if ($parent_term->parent) {
                                $parent_id = $parent_term->parent;
                            }
                            else {
                                $has_parent = false;
                            }

                            break;
                        }
                    }
                }
            }

            // Get term id
            $term_id = (string) $term->term_id;

            // Skip this item if we don't need it
            if (!empty($ids) && !in_array($term_id, $ids, true)) {
                continue;
            }

            // Add item
            $items[] = array(
                'id'    => $term_id,
                'text'  => $term_name
            );
        }

        return $items;
    }

    /**
     * Get all non-hierarchical taxonomy terms
     *
     * @access public
     * @param string $taxonomy
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_non_hierarchical_taxonomy_terms($taxonomy, $ids = array(), $query = '')
    {
        $items = array();

        // Get terms
        $terms = get_terms(array($taxonomy), array('hide_empty' => 0));

        // Iterate over terms
        foreach ($terms as $term_key => $term) {

            // Get term id
            $term_id = (string) $term->term_id;

            // Skip this item if we don't need it
            if (!empty($ids) && !in_array($term_id, $ids, true)) {
                continue;
            }

            // Add item
            $items[] = array(
                'id'    => $term_id,
                'text'  => $term->name,
            );
        }

        return $items;
    }

    /**
     * Get all capabilities based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @param bool $include_custom_user_caps
     * @return array
     */
    public static function get_all_capabilities($ids = array(), $query = '', $include_custom_user_caps = false)
    {
        global $wpdb;
        global $wp_roles;

        $items = array();

        // Groups plugin active?
        if (class_exists('Groups_User') && class_exists('Groups_Wordpress') && function_exists('_groups_get_tablename')) {

            $capability_table = _groups_get_tablename('capability');
            $all_capabilities = $wpdb->get_results('SELECT capability FROM ' . $capability_table);

            if ($all_capabilities) {
                foreach ($all_capabilities as $capability) {

                    $capability = (string) $capability->capability;

                    // Skip this item if we don't need it
                    if (!empty($ids) && !in_array($capability, $ids, true)) {
                        continue;
                    }

                    // Add item
                    $items[] = array(
                        'id'    => $capability,
                        'text'  => $capability
                    );
                }
            }
        }

        // Get standard WP capabilities
        else {

            if (!isset($wp_roles)) {
                get_role('administrator');
            }

            $roles = $wp_roles->roles;

            $already_added = array();

            if (is_array($roles)) {

                // Iterate over roles
                foreach ($roles as $rolename => $atts) {
                    if (isset($atts['capabilities']) && is_array($atts['capabilities'])) {
                        foreach ($atts['capabilities'] as $capability => $value) {

                            $capability = (string) $capability;

                            if (!in_array($capability, $already_added, true)) {

                                // Skip this item if we don't need it
                                if (!empty($ids) && !in_array($capability, $ids, true)) {
                                    continue;
                                }

                                // Add item
                                $items[] = array(
                                    'id'    => $capability,
                                    'text'  => $capability
                                );
                                $already_added[] = $capability;
                            }
                        }
                    }
                }

                // Get custom capabilities assigned to individual users
                if ($include_custom_user_caps) {

                    // Get role names
                    $role_names = array_keys($roles);

                    // Get raw capability data for all users
                    $raw_capabilities = $wpdb->get_col("SELECT DISTINCT `meta_value` FROM `{$wpdb->prefix}usermeta` WHERE `meta_key` LIKE '{$wpdb->prefix}capabilities'");

                    // Add custom user capabilities to the list
                    foreach ($raw_capabilities as $raw_capability) {

                        // Unserialize raw capability entry
                        $unserialized = maybe_unserialize($raw_capability);

                        // Iterate over capabilities of current entry
                        if (is_array($unserialized)) {
                            foreach ($unserialized as $capability => $value) {

                                $capability = (string) $capability;

                                // Check if it's not a role name and was not already added
                                if (!in_array($capability, $role_names, true) && !in_array($capability, $already_added, true)) {

                                    // Skip this item if we don't need it
                                    if (!empty($ids) && !in_array($capability, $ids, true)) {
                                        continue;
                                    }

                                    // Add item
                                    $items[] = array(
                                        'id'    => $capability,
                                        'text'  => $capability
                                    );
                                    $already_added[] = $capability;
                                }
                            }
                        }
                    }
                }

            }
        }

        // Note: callbacks must return array of arrays with id/text properties set
        return apply_filters('rightpress_all_user_capabilities', $items);
    }

    /**
     * Get all countries based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_countries($ids = array(), $query = '')
    {
        $items = array();

        $countries = new WC_Countries();

        // Iterate over all countries
        if ($countries && is_array($countries->countries)) {
            foreach ($countries->countries as $country_code => $country_name) {

                // Add item
                $items[] = array(
                    'id'    => (string) $country_code,
                    'text'  => $country_name,
                );
            }
        }

        return $items;
    }

    /**
     * Get all coupons based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_coupons($ids = array(), $query = '')
    {
        $items = array();

        // Get all coupon ids
        $args = array(
            'posts_per_page'    => -1,
            'post_type'         => 'shop_coupon',
            'post_status'       => array('publish'),
            'fields'            => 'ids',
        );

        // Specific coupons requested
        if (!empty($ids)) {
            $args['post__in'] = $ids;
        }

        // WC31: As of WC 3.4 there are no coupon query methods and coupons are still treated as posts in WooCommerce core
        $posts_raw = get_posts($args);

        // Format results array
        foreach ($posts_raw as $post_id) {
            $items[] = array(
                'id'    => (string) $post_id,
                'text'  => get_the_title($post_id)
            );
        }

        return $items;
    }

    /**
     * Get all weekdays based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_weekdays($ids = array(), $query = '')
    {
        $items = array();

        // Get weekdays
        foreach (RightPress_Help::get_weekdays() as $weekday_key => $weekday) {

            // Add weekday
            $items[] = array(
                'id'    => (string) $weekday_key,
                'text'  => $weekday
            );
        }

        return $items;
    }

    /**
     * Get all product attributes based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_product_attributes($ids = array(), $query = '')
    {
        global $wc_product_attributes;

        $items = array();

        // Iterate over product attributes
        foreach ($wc_product_attributes as $attribute_key => $attribute) {

            // Get attribute name
            $attribute_name = !empty($attribute->attribute_label) ? $attribute->attribute_label : $attribute->attribute_name;

            // Get terms for this attribute
            $terms = RightPress_Conditions::get_all_hierarchical_taxonomy_terms($attribute_key, $ids, $query);

            // Iterate over subitems and make a list of item/subitem pairs
            foreach ($terms as $term) {
                $items[] = array(
                    'id'    => $term['id'],
                    'text'  => $attribute_name . ': ' . $term['text'],
                );
            }
        }

        return $items;
    }

    /**
     * Get all product categories based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_product_categories($ids = array(), $query = '')
    {
        // WC31: As of WC 3.4 product categories are still WP taxonomy terms
        return RightPress_Conditions::get_all_hierarchical_taxonomy_terms('product_cat', $ids, $query);
    }

    /**
     * Get all product tags based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_product_tags($ids = array(), $query = '')
    {
        // WC31: As of WC 3.4 product tags are still WP taxonomy terms
        return RightPress_Conditions::get_all_non_hierarchical_taxonomy_terms('product_tag', $ids, $query);
    }

    /**
     * Get all product variations based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_product_variations($ids = array(), $query = '')
    {
        $items = array();

        // Search product variations by query
        if ($query !== '') {

            // Load data stores
            $data_store = WC_Data_Store::load('product');

            // Search for variations
            // Note: search will also return other product types, we will filter them out later
            $variation_ids = $data_store->search_products($query, '', true, true);
        }
        // Get variations by ids or all variations if ids were not provided
        else {

            $variation_ids = wc_get_products(array(
                'include'   => $ids,
                'type'      => 'variation',
                'orderby'   => 'title',
                'order'     => 'ASC',
                'return'    => 'ids',
                'limit'     => -1,
            ));
        }

        // Format items
        foreach ($variation_ids as $variation_id) {

            // Load variation
            if ($variation = wc_get_product($variation_id)) {

                // Filter out other product types (search in data store may return mixed results)
                if ($variation->is_type('variation')) {

                    // Get list of variation attributes
                    $attributes = $variation->get_variation_attributes();

                    // Change empty values
                    foreach ($attributes as $attribute_key => $attribute) {
                        if ($attribute === '') {
                            $attributes[$attribute_key] = sprintf(strtolower(__('Any %s', 'woocommerce')), wc_attribute_label(str_replace('attribute_', '', $attribute_key)));
                        }
                    }

                    // Join attributes
                    $attributes = join(', ', $attributes);
                    $attributes = RightPress_Help::shorten_text($attributes, 25);

                    // Get variation identifier
                    if ($variation->get_sku()) {
                        $identifier = $variation->get_sku();
                    } else {
                        $identifier = '#' . $variation->get_id();
                    }

                    // Format variation title for display
                    $variation_title = $variation->get_title() . ' - ' . $attributes . ' (' . $identifier . ')';

                    // Add variation
                    $items[] = array(
                        'id'    => (string) $variation->get_id(),
                        'text'  => rawurldecode($variation_title),
                    );
                }
            }
        }

        return $items;
    }

    /**
     * Get all products based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_products($ids = array(), $query = '')
    {
        $items = array();

        // Search products by query
        if ($query !== '') {

            // Load data stores
            $data_store = WC_Data_Store::load('product');

            // Search for products
            $product_ids = $data_store->search_products($query, '', false, true);
        }
        // Get products by ids or all products if ids were not provided
        else {

            $product_ids = wc_get_products(array(
                'include'   => $ids,
                'orderby'   => 'title',
                'order'     => 'ASC',
                'return'    => 'ids',
                'limit'     => -1,
            ));
        }

        // Format items
        foreach ($product_ids as $product_id) {

            // Load product
            if ($product = wc_get_product($product_id)) {

                // Add to items array
                $items[] = array(
                    'id'    => (string) $product->get_id(),
                    'text'  => rawurldecode($product->get_formatted_name()),
                );
            }
        }

        return $items;
    }

    /**
     * Get all roles based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_roles($ids = array(), $query = '')
    {
        $items = array();

        // Get roles
        global $wp_roles;

        if (!isset($wp_roles)) {
            $wp_roles = new WP_Roles();
        }

        // Iterate over roles and format results array
        foreach ($wp_roles->get_names() as $role_key => $role) {

            $role_key = (string) $role_key;

            // Skip this item if we don't need it
            if (!empty($ids) && !in_array($role_key, $ids, true)) {
                continue;
            }

            // Add item
            $items[] = array(
                'id'    => $role_key,
                'text'  => $role . ' (' . $role_key . ')',
            );
        }

        return $items;
    }

    /**
     * Get all shipping zones based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_shipping_zones($ids = array(), $query = '')
    {
        $items = array();

        // Iterate over shipping zones
        foreach (WC_Shipping_Zones::get_zones() as $shipping_zone) {

            // Add item
            $items[] = array(
                'id'    => (string) $shipping_zone['zone_id'],
                'text'  => $shipping_zone['zone_name'],
            );
        }

        // Get Rest of the World shipping zone
        $shipping_zone = WC_Shipping_Zones::get_zone(0);

        // Add Rest of the World shipping zone
        $items = array_merge(array(array(
            'id'    => (string) $shipping_zone->get_id(),
            'text'  => $shipping_zone->get_zone_name(),
        )), $items);

        return $items;
    }

    /**
     * Get all states based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_states($ids = array(), $query = '')
    {
        $items = array();

        $countries = new WC_Countries();
        $all_states = $countries->get_states();

        // Iterate over all countries
        if ($countries && is_array($countries->countries) && is_array($all_states)) {
            foreach ($all_states as $country_key => $states) {
                if (is_array($states) && !empty($states)) {

                    // Get country name
                    $country_name = !empty($countries->countries[$country_key]) ? $countries->countries[$country_key] : $country_key;

                    // Iterate over all states
                    foreach ($states as $state_key => $state) {

                        // Add item
                        $items[] = array(
                            'id'    => $country_key . '_' . $state_key,
                            'text'  => $country_name . ': ' . $state,
                        );
                    }
                }
            }
        }

        return $items;
    }

    /**
     * Get all users based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_users($ids = array(), $query = '')
    {
        $items = array();

        // Get users
        $users = get_users(array(
            'fields' => array('ID', 'user_login', 'user_email'),
        ));

        // Iterate over users
        foreach ($users as $user) {

            // Add item
            $items[] = array(
                'id'    => (string) $user->ID,
                'text'  => '#' . $user->ID . ' ' . $user->user_login . ' (' . $user->user_email . ')',
            );
        }

        return $items;
    }

    /**
     * Get all payment methods based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_payment_methods($ids = array(), $query = '')
    {
        $items = array();

        global $woocommerce;

        // Load payment gateways class
        $gateways = $woocommerce->payment_gateways();

        // Iterate over all payment gateways
        foreach ($gateways->payment_gateways() as $gateway_key => $gateway) {

            // Get method title
            $method_title = $gateway->get_method_title();

            // Get custom title
            if (!empty($gateway->title) && is_string($gateway->title) && $gateway->title !== $method_title) {
                $method_title .= ' (' . $gateway->title . ')';
            }

            // Add item
            $items[] = array(
                'id'    => (string) $gateway_key,
                'text'  => $method_title,
            );
        }

        return $items;
    }

    /**
     * Get all shipping methods based on criteria
     *
     * @access public
     * @param array $ids
     * @param string $query
     * @return array
     */
    public static function get_all_shipping_methods($ids = array(), $query = '')
    {
        $items = array();

        global $woocommerce;

        // Load shipping methods
        $woocommerce->shipping->load_shipping_methods();

        // Get shipping methods
        $shipping_methods = $woocommerce->shipping->get_shipping_methods();

        // Iterate over shipping methods
        if (is_array($shipping_methods) && !empty($shipping_methods)) {
            foreach ($shipping_methods as $shipping_method) {

                // Add item
                $items[] = array(
                    'id'    => (string) $shipping_method->id,
                    'text'  => $shipping_method->method_title,
                );
            }
        }

        return $items;
    }

    /**
     * Get order ids
     *
     * @access public
     * @param array $params
     * @return array
     */
    public static function get_order_ids($params = array())
    {
        global $woocommerce;

        $order_ids = array();
        $config = array();

        // Get date object
        if (isset($params['date'])) {
            $config['date'] = $params['date'];
        }

        // Only paid orders are counted
        $config['status'] = RightPress_Help::get_wc_order_is_paid_statuses(true);

        // Get customer id
        $customer_id = isset($params['customer_id']) ? $params['customer_id'] : get_current_user_id();

        // Get customer billing email
        if ($customer_id) {
            $customer = new WC_Customer($customer_id);
            $billing_email = $customer->get_billing_email();
        }
        else {
            $billing_email = RightPress_Conditions::get_checkout_billing_email();
        }

        // Get order ids by customer id
        if ($customer_id) {
            $order_ids = RightPress_Help::get_wc_order_ids(array_merge($config, array('customer_id' => $customer_id)));
        }

        // Get order ids by billing email
        if ($billing_email) {
            $order_ids = array_merge($order_ids, RightPress_Help::get_wc_order_ids(array_merge($config, array('billing_email' => $billing_email))));
        }

        // Return order ids
        return array_unique($order_ids);
    }

    /**
     * Get billing email from checkout data
     *
     * @access public
     * @return string|bool
     */
    public static function get_checkout_billing_email()
    {
        // Check for specific ajax requests
        if (!empty($_GET['wc-ajax']) && in_array($_GET['wc-ajax'], array('update_order_review', 'checkout'), true)) {

            $billing_email = null;

            // Check if request contains billing email
            if (!empty($_POST['billing_email'])) {
                $billing_email = $_POST['billing_email'];
            }
            else if (!empty($_POST['post_data'])) {

                parse_str($_POST['post_data'], $checkout_data);

                if (!empty($checkout_data['billing_email'])) {
                    $billing_email = $checkout_data['billing_email'];
                }
            }

            // Validate billing email format
            if (filter_var($billing_email, FILTER_VALIDATE_EMAIL)) {
                return $billing_email;
            }
        }

        return null;
    }

    /**
     * Check postcode
     *
     * @access public
     * @param string $value
     * @param string $condition_value
     * @return bool
     */
    public static function check_postcode($value, $condition_value)
    {
        // Neither can be empty
        if (RightPress_Help::is_empty($value) || RightPress_Help::is_empty($condition_value)) {
            return false;
        }

        // Break up condition postcode string
        $postcodes = explode(',', $condition_value);

        // Iterate over postcodes
        foreach ($postcodes as $postcode) {

            // Clean value
            $postcode = trim($postcode);

            // Postcode is empty
            if (RightPress_Help::is_empty($postcode)) {
                continue;
            }

            // Postcode with wildcards
            if (strpos($postcode, '*') !== false) {

                // Prepare regex string
                $regex = '/^' . str_replace('\*', '.', preg_quote($postcode)) . '$/i';

                // Compare
                if (preg_match($regex, $value) === 1) {
                    return true;
                }
            }
            // Postcode range
            else if (strpos($postcode, '-') !== false) {

                // Split range
                $ranges = explode('-', $postcode);
                $ranges[0] = trim($ranges[0]);
                $ranges[1] = trim($ranges[1]);

                // Check if ranges are valid
                if (count($ranges) !== 2 || (empty($ranges[0]) && $ranges[0] !== '0') || (empty($ranges[1]) && $ranges[1] !== '0') || !is_numeric($ranges[0]) || !is_numeric($ranges[1]) || $ranges[0] >= $ranges[1]) {
                    continue;
                }

                // Check if post code is within ranges
                if ($ranges[0] <= $value && $value <= $ranges[1]) {
                    return true;
                }
            }
            // Full postcode
            else if ($postcode === $value) {
                return true;
            }
        }

        // Postcode doesn't match
        return false;
    }

    /**
     * Get order total for use in conditions
     *
     * Attempts to get order total in base currency if another currency
     * was used for an order
     *
     * @access public
     * @param mixed $order
     * @return float
     */
    public static function order_get_total($order)
    {
        // Load order object
        if (!is_a($order, 'WC_Order')) {
            $order = wc_get_order($order);
        }

        // Order has different currency than base currency
        if ($order_total = RightPress_Help::get_wc_order_total_in_base_currency($order)) {
            return (float) $order_total;
        }
        // Get total in a regular way
        else {
            return (float) $order->get_total();
        }
    }



}
}