Plugin Directory

Changeset 958980


Ignore:
Timestamp:
08/01/2014 10:27:46 PM (12 years ago)
Author:
splashingpixels.com
Message:

added region and city filters

Location:
woocommerce-geolocation-based-products/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-geolocation-based-products/trunk/includes/class-wc-geolocation-based-products-admin.php

    r948488 r958980  
    8888                $countrys = isset( $row['countrys'] ) ? strtoupper( sanitize_text_field( $row['countrys'] ) ) : '';
    8989
     90                $regions = isset( $row['regions'] ) ? strtoupper( sanitize_text_field( $row['regions'] ) ) : '';
     91
     92                $cities = isset( $row['cities'] ) ? strtoupper( sanitize_text_field( $row['cities'] ) ) : '';
     93
    9094                if ( isset( $row['product_categories'] ) ) {
    9195                    $product_categories = is_array( $row['product_categories'] ) ? array_map( 'absint', $row['product_categories'] ) : absint( $row['   product_categories'] );
     
    9599
    96100                if ( isset( $row['products'] ) ) {
    97                     $products = is_array( $row['products']) ? array_map( 'absint', $row['products']) : absint( $row['products']);
     101                    $products = is_array( $row['products'] ) ? array_map( 'absint', $row['products'] ) : absint( $row['products'] );
    98102                } else {
    99103                    $products = array();
    100104                }
    101105
     106                if ( isset( $row['test'] ) ) {
     107                    $test = is_array( $row['test'] ) ? array_map( 'sanitize_text_field', $row['test'] ) : sanitize_text_field( $row['test'] );
     108                } else {
     109                    $test = array();
     110                }
     111
    102112                $rows[] = array(
    103                     'countrys'           => $countrys,
     113                    'countrys'           => $countrys,
     114                    'regions'            => $regions,
     115                    'cities'             => $cities,
    104116                    'product_categories' => $product_categories,
    105                     'products'           => $products
     117                    'products'           => $products,
     118                    'test'               => $test
    106119                );
    107120            }
     
    109122            // update options
    110123            update_option( 'wc_geolocation_based_products_settings', $rows );
    111 
    112             // test country
    113             $test_country = strtoupper( sanitize_text_field( $_POST['test_country'] ) );
    114 
    115             update_option( 'wc_geolocation_based_products_test_country', $test_country );
    116124        }
    117125
     
    132140
    133141        $cats = $this->get_product_categories();
    134 
    135         $test_country = get_option( 'wc_geolocation_based_products_test_country', false );
    136142        ?>
    137143        <table class="wc-geolocation-based-products-settings widefat">
     
    140146                    <th><?php _e( 'Remove', 'woocommerce-geolocation-based-products' ); ?></th>
    141147
    142                     <th width="8%"><?php _e( 'Country&nbsp;Code', 'woocommerce-geolocation-based-products' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'A 2 letter country code, e.g. US. Leave blank to disable.', 'woocommerce-geolocation-based-products' ); ?>">[?]</span></th>
    143 
    144                     <th width="45%"><?php _e( 'Product Categories to Hide', 'woocommerce-geolocation-based-products' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'Select all the product categories in which you want to hide for this country.', 'woocommerce-geolocation-based-products' ); ?>">[?]</span></th>
    145 
    146                     <th width="45%"><?php _e( 'Products to Hide', 'woocommerce-geolocation-based-products' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'Search for the products in which you want to hide for this country.', 'woocommerce-geolocation-based-products' ); ?>">[?]</span></th>
     148                    <th width="5%"><?php _e( 'Country Code', 'woocommerce-geolocation-based-products' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'A 2 letter country code, e.g. US.  This is required. Leave blank to disable.', 'woocommerce-geolocation-based-products' ); ?>">[?]</span></th>
     149
     150                    <th width="10%"><?php _e( 'Region Code', 'woocommerce-geolocation-based-products' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'A region code for your state or province, e.g. CA for California. Leave blank to disable.', 'woocommerce-geolocation-based-products' ); ?>">[?]</span></th>
     151
     152                    <th width="18%"><?php _e( 'City', 'woocommerce-geolocation-based-products' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'A city name. Leave blank to disable.', 'woocommerce-geolocation-based-products' ); ?>">[?]</span></th>
     153
     154                    <th width="30%"><?php _e( 'Product Categories to Hide', 'woocommerce-geolocation-based-products' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'Select all the product categories in which you want to hide for this country.', 'woocommerce-geolocation-based-products' ); ?>">[?]</span></th>
     155
     156                    <th width="30%"><?php _e( 'Products to Hide', 'woocommerce-geolocation-based-products' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'Search for the products in which you want to hide for this country.', 'woocommerce-geolocation-based-products' ); ?>">[?]</span></th>
     157
     158                    <th width="2%"><?php _e( 'Test Mode', 'woocommerce-geolocation-based-products' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'Check the box to enable test mode for this rule. Leave blank to disable.', 'woocommerce-geolocation-based-products' ); ?>">[?]</span></th>
    147159                </tr>
    148160            </thead>
     
    164176                            </td>
    165177
    166                             <td class="country" width="8%">
     178                            <td class="country" width="5%">
    167179                                <input type="text" name="row[0][countrys]" value="" placeholder="<?php esc_attr_e( '2 Letter Country Code', 'woocommerce-geolocation-based-products' ); ?>" maxlength="2" class="wc-geolocation-based-products-country" />
    168180                            </td>
    169181
    170                             <td class="product-categories" width="45%">
     182                            <td class="region" width="10%">
     183                                <input type="text" name="row[0][regions]" value="" placeholder="<?php esc_attr_e( 'Region Code', 'woocommerce-geolocation-based-products' ); ?>" class="wc-geolocation-based-products-region" />
     184                            </td>
     185
     186                            <td class="city" width="18%">
     187                                <input type="text" name="row[0][cities]" value="" placeholder="<?php esc_attr_e( 'City Name', 'woocommerce-geolocation-based-products' ); ?>" class="wc-geolocation-based-products-city" />
     188                            </td>
     189
     190                            <td class="product-categories" width="30%">
    171191                                <select name="row[0][product_categories][]" class="wc-geolocation-based-products-choose-product-categories" multiple="multiple" data-placeholder="<?php _e( 'Select Product Categories', 'woocommerce-geolocation-based-products' ); ?>">
    172192                                    <option value=""></option>
     
    183203                            </td>
    184204
    185                             <td class="products" width="45%">
     205                            <td class="products" width="30%">
    186206                                <select name="row[0][products][]" class="wc-geolocation-based-products-choose-products" multiple="multiple" data-placeholder="<?php _e( 'Search Products by Name', 'woocommerce-geolocation-based-products' ); ?>">
    187207                                    <option value=""></option>
    188208                                </select>
     209                            </td>
     210
     211                            <td class="test" width="2%">
     212                                <input type="checkbox" name="row[0][test]" value="" class="wc-geolocation-based-products-test" />
    189213                            </td>
    190214                        </tr>
     
    196220
    197221                            $countrys = ( isset( $row['countrys'] ) && ! empty( $row['countrys'] ) ) ? $row['countrys'] : '';
     222
     223                            $regions = ( isset( $row['regions'] ) && ! empty( $row['regions'] ) ) ? $row['regions'] : '';
     224
     225                            $cities = ( isset( $row['cities'] ) && ! empty( $row['cities'] ) ) ? $row['cities'] : '';
     226
     227                            $test = ( isset( $row['test'] ) && ! empty( $row['test'] ) ) ? $row['test'] : '';
    198228                ?>
    199229                            <tr class="entry">
     
    202232                                </td>
    203233
    204                                 <td class="country" width="8%">
     234                                <td class="country" width="5%">
    205235                                    <input type="text" name="row[<?php echo esc_attr( $row_count ); ?>][countrys]" value="<?php echo esc_attr( $countrys ); ?>" placeholder="<?php esc_attr_e( '2 Letter Country Code', 'woocommerce-geolocation-based-products' ); ?>" maxlength="2" class="wc-geolocation-based-products-country" />
    206236                                </td>
    207237
    208                                 <td class="product-categories" width="45%">
     238                                <td class="region" width="10%">
     239                                    <input type="text" name="row[<?php echo esc_attr( $row_count ); ?>][regions]" value="<?php echo esc_attr( $regions ); ?>" placeholder="<?php esc_attr_e( 'Region Code', 'woocommerce-geolocation-based-products' ); ?>" class="wc-geolocation-based-products-region" />
     240                                </td>
     241
     242                                <td class="city" width="18%">
     243                                    <input type="text" name="row[<?php echo esc_attr( $row_count ); ?>][cities]" value="<?php echo esc_attr( $cities ); ?>" placeholder="<?php esc_attr_e( 'City Name', 'woocommerce-geolocation-based-products' ); ?>" class="wc-geolocation-based-products-city" />
     244                                </td>
     245
     246                                <td class="product-categories" width="30%">
    209247                                    <select name="row[<?php echo esc_attr( $row_count ); ?>][product_categories][]" class="wc-geolocation-based-products-choose-product-categories" multiple="multiple" data-placeholder="<?php _e( 'Select Product Categories', 'woocommerce-geolocation-based-products' ); ?>">
    210248                                        <option value=""></option>
     
    222260                                </td>
    223261
    224                                 <td class="products" width="45%">
     262                                <td class="products" width="30%">
    225263                                    <select name="row[<?php echo esc_attr( $row_count ); ?>][products][]" class="wc-geolocation-based-products-choose-products" multiple="multiple" data-placeholder="<?php _e( 'Search Products by Name', 'woocommerce-geolocation-based-products' ); ?>">
    226264                                        <option value=""></option>
     
    241279                                    </select>
    242280                                </td>
     281
     282                                <td class="test" width="2%">
     283                                    <input type="checkbox" name="row[<?php echo esc_attr( $row_count ); ?>][test]" value="true" class="wc-geolocation-based-products-test" <?php checked( 'true', $test ); ?> />
     284                                </td>
    243285                            </tr>
    244286                <?php
     
    249291            </tbody>
    250292        </table>
    251 
    252         <h3><?php _e( 'Simulate Country Test', 'woocommerce-geolocation-based-products' ); ?></h3>
    253         <p><label><?php _e( 'Enter a 2 letter country code to simulate the test.  Remember to remove when done testing.', 'woocommerce-geolocation-based-products' ); ?></label><br />
    254             <input type="text" name="test_country" value="<?php echo esc_attr( $test_country ); ?>" placeholder="<?php esc_attr_e( '2 Letter Country Code', 'woocommerce-geolocation-based-products' ); ?>" maxlength="2" />
    255         </p>
    256293        <?php
    257294    }
  • woocommerce-geolocation-based-products/trunk/includes/class-wc-geolocation-based-products-frontend.php

    r948488 r958980  
    55
    66class WC_Geolocation_Based_Products_Frontend {
     7
     8    var $location_data;
     9    var $exclusion;
     10
    711    /**
    812     * init
     
    1519
    1620        add_action( 'pre_get_posts', array( $this, 'filter_query' ) );
    17 
    18         add_filter( 'wc_geolocation_based_products_user_country', array( $this, 'filter_user_country' ) );
    1921
    2022        // hide from category view
    2123        add_filter( 'woocommerce_product_subcategories_args', array( $this, 'hide_categories_view' ) );
    2224
     25        $this->location_data = $this->get_location_data();
     26
     27        $this->exclusion = $this->get_exclusion();
     28
    2329        return true;
    2430    }
     
    3238     */
    3339    public function get_user_country() {
    34         $ip_data = $this->get_location_data();
    35 
    36         $user_country = apply_filters( 'wc_geolocation_based_products_user_country', $ip_data['countryCode'] );
     40        $user_country = apply_filters( 'wc_geolocation_based_products_user_country', $this->location_data['countryCode'] );
    3741
    3842        return $user_country;
     43    }
     44
     45    /**
     46     * gets the user region
     47     *
     48     * @access public
     49     * @since 1.1.0
     50     * @return string $user_region
     51     */
     52    public function get_user_region() {
     53        $user_region = apply_filters( 'wc_geolocation_based_products_user_region', $this->location_data['region'] );
     54
     55        return $user_region;
     56    }
     57
     58    /**
     59     * gets the user city
     60     *
     61     * @access public
     62     * @since 1.1.0
     63     * @return string $user_city
     64     */
     65    public function get_user_city() {
     66        $user_city = apply_filters( 'wc_geolocation_based_products_user_city', $this->location_data['city'] );
     67
     68        return $user_city;
    3969    }
    4070
     
    5282
    5383        $products = array();
    54 
    55         $user_country = $this->get_user_country();
    5684
    5785        $rows = get_option( 'wc_geolocation_based_products_settings', false );
     
    6088            // loop through the rows and get data
    6189            foreach( $rows as $row ) {
    62                 // match the country of ip with saved settings
    63                 if ( $row['countrys'] === $user_country ) {
     90                $exclude = false;
     91
     92                // check if test is enabled
     93                if ( isset( $row['test'] ) && $row['test'] === 'true' ) {
    6494                    $exclude = true;
    6595
     96                } else {
     97
     98                    // check if country is set and matched
     99                    if ( $this->country_is_matched( $row['countrys'] ) && ( $this->region_isset( $row['regions'] ) || $this->city_isset( $row['cities'] ) ) ) {
     100                        // if both region and city is set they both have to match
     101                        if ( $this->region_isset( $row['regions'] ) && $this->city_isset( $row['cities'] ) ) {
     102                            if ( $this->region_is_matched( $row['regions'] ) && $this->city_is_matched( $row['cities'] ) ) {
     103                                $exclude = true;
     104                            }
     105                        } elseif ( $this->region_isset( $row['regions'] ) ) {
     106                            if ( $this->region_is_matched( $row['regions'] ) ) {
     107                                $exclude = true;
     108                            }   
     109                        } elseif ( $this->city_isset( $row['cities'] ) ) {
     110                            if ( $this->city_is_matched( $row['cities'] ) ) {
     111                                $exclude = true;
     112                            }
     113                        }
     114                    } elseif ( $this->country_is_matched( $row['countrys'] ) ) {
     115                        $exclude = true;
     116                    }
     117                }
     118
     119                if ( $exclude ) {
    66120                    $product_cats = $row['product_categories'];
    67121
    68                     $products = $row['products'];
     122                    $products = $row['products'];   
     123
     124                    break; // after a match no need to look at the rest             
    69125                }
    70126            }
     
    73129        if ( $exclude ) {
    74130            return array( 'product_cats' => $product_cats, 'products' => $products );
     131        } else {
     132            return false;
     133        }
     134    }
     135
     136    /**
     137     * checks if country matches current user's country
     138     *
     139     * @access public
     140     * @since 1.1.0
     141     * @param string $saved_country | saved country setting to match
     142     * @return bool
     143     */
     144    public function country_is_matched( $saved_country ) {
     145        $user_country = $this->location_data['countryCode'];
     146
     147        if ( isset( $saved_country ) && ! empty( $saved_country ) && strtolower( $saved_country ) === strtolower( $user_country ) ) {
     148            return true;
     149        } else {
     150            return false;
     151        }
     152    }
     153
     154    /**
     155     * checks if country isset
     156     *
     157     * @access public
     158     * @since 1.1.0
     159     * @param string $saved_country | saved country setting to match
     160     * @return bool
     161     */
     162    public function country_isset( $saved_country ) {
     163        if ( isset( $saved_country ) && ! empty( $saved_country ) ) {
     164            return true;
     165        } else {
     166            return false;
     167        }
     168    }
     169
     170    /**
     171     * checks if region matches current user's region
     172     *
     173     * @access public
     174     * @since 1.1.0
     175     * @param string $saved_region | saved region setting to match
     176     * @return bool
     177     */
     178    public function region_is_matched( $saved_region ) {
     179        $user_region = $this->location_data['region'];
     180
     181        if ( isset( $saved_region ) && ! empty( $saved_region ) && strtolower( $saved_region ) === strtolower( $user_region ) ) {
     182            return true;
     183        } else {
     184            return false;
     185        }
     186    }
     187
     188    /**
     189     * checks if region isset
     190     *
     191     * @access public
     192     * @since 1.1.0
     193     * @param string $saved_region | saved region setting to match
     194     * @return bool
     195     */
     196    public function region_isset( $saved_region ) {
     197        if ( isset( $saved_region ) && ! empty( $saved_region ) ) {
     198            return true;
     199        } else {
     200            return false;
     201        }
     202    }
     203
     204    /**
     205     * checks if city matches current user's city
     206     *
     207     * @access public
     208     * @since 1.1.0
     209     * @param string $saved_city | saved city setting to match
     210     * @return bool
     211     */
     212    public function city_is_matched( $saved_city ) {
     213        $user_city = $this->location_data['city'];
     214
     215        if ( isset( $saved_city ) && ! empty( $saved_city ) && strtolower( $saved_city ) === strtolower( $user_city ) ) {
     216            return true;
     217        } else {
     218            return false;
     219        }
     220    }
     221
     222    /**
     223     * checks if city isset
     224     *
     225     * @access public
     226     * @since 1.1.0
     227     * @param string $saved_city | saved city setting to match
     228     * @return bool
     229     */
     230    public function city_isset( $saved_city ) {
     231        if ( isset( $saved_city ) && ! empty( $saved_city ) ) {
     232            return true;
    75233        } else {
    76234            return false;
     
    92250        }
    93251
    94         $exclusion = $this->get_exclusion();
    95 
    96         if ( $exclusion ) {
     252        if ( $this->exclusion ) {
    97253            $taxquery = array(
    98254                array(
    99255                    'taxonomy' => 'product_cat',
    100256                    'field'    => 'id',
    101                     'terms'    => $exclusion['product_cats'],
     257                    'terms'    => $this->exclusion['product_cats'],
    102258                    'operator' => 'NOT IN'
    103259                )
     
    106262            $q->set( 'tax_query', $taxquery );
    107263
    108             $q->set( 'post__not_in', $exclusion['products'] );
     264            $q->set( 'post__not_in', $this->exclusion['products'] );
    109265        } else {
    110266            return;
     
    120276     */
    121277    public function hide_categories_view( $args ) {
    122         $exclusion = $this->get_exclusion();
    123 
    124         if ( $exclusion ) {
    125             $args['exclude'] = implode( ',', $exclusion['product_cats'] );
     278        if ( $this->exclusion ) {   
     279            $args['exclude'] = implode( ',', $this->exclusion['product_cats'] );
    126280        }
    127281
    128282        return $args;
    129     }
    130 
    131     /**
    132      * filters the user country for testing
    133      *
    134      * @access public
    135      * @since 1.0.0
    136      * @param string
    137      * @return string $test_country
    138      */
    139     public function filter_user_country( $ip_country ) {
    140         $test_country = get_option( 'wc_geolocation_based_products_test_country', false );
    141 
    142         if ( $test_country && ! empty( $test_country ) ) {
    143             return $test_country;
    144         } else {
    145             return $ip_country;
    146         }
    147283    }
    148284
     
    168304        ) );
    169305       
    170         $response = wp_remote_get( $url, $args );
     306        $response = wp_remote_post( $url, $args );
    171307
    172308        $response_body = @maybe_unserialize( wp_remote_retrieve_body( $response ) );
  • woocommerce-geolocation-based-products/trunk/plugin-assets/js/admin-settings.js

    r948488 r958980  
    4242            // re-init row positions
    4343            $( 'table.wc-geolocation-based-products-settings' ).find( 'tr.entry' ).each( function( row ) {
     44                // reinit row position country
    4445                var rowPos = String( $( 'input.wc-geolocation-based-products-country', this ).prop( 'name' ) ),
    4546                    replacedName = rowPos.replace( /row\[\d+\]/, 'row[' + row + ']' );
     
    4748                $( 'input.wc-geolocation-based-products-country', this ).prop( 'name', replacedName );
    4849
     50                // reinit row position region
     51                rowPos = String( $( 'input.wc-geolocation-based-products-region', this ).prop( 'name' ) );
     52                replacedName = rowPos.replace( /row\[\d+\]/, 'row[' + row + ']' );
     53
     54                $( 'input.wc-geolocation-based-products-region', this ).prop( 'name', replacedName );
     55
     56                // reinit row position city
     57                rowPos = String( $( 'input.wc-geolocation-based-products-city', this ).prop( 'name' ) );
     58                replacedName = rowPos.replace( /row\[\d+\]/, 'row[' + row + ']' );
     59
     60                $( 'input.wc-geolocation-based-products-city', this ).prop( 'name', replacedName );
     61
     62                // reinit row position products
    4963                rowPos = String( $( 'select.wc-geolocation-based-products-choose-products', this ).prop( 'name' ) );
    5064                replacedName = rowPos.replace( /row\[\d+\]/, 'row[' + row + ']' );
     
    5266                $( 'select.wc-geolocation-based-products-choose-products', this ).prop( 'name', replacedName );
    5367
     68                // reinit row position product categories
    5469                rowPos = String( $( 'select.wc-geolocation-based-products-choose-product-categories', this ).prop( 'name' ) );
    5570                replacedName = rowPos.replace( /row\[\d+\]/, 'row[' + row + ']' );
    5671
    5772                $( 'select.wc-geolocation-based-products-choose-product-categories', this ).prop( 'name', replacedName );
     73
     74                // reinit row position test
     75                rowPos = String( $( 'input.wc-geolocation-based-products-test', this ).prop( 'name' ) );
     76                replacedName = rowPos.replace( /row\[\d+\]/, 'row[' + row + ']' );
     77
     78                $( 'input.wc-geolocation-based-products-test', this ).prop( 'name', replacedName );
    5879            });
    5980        },
     
    7798                // remove any checkmark
    7899                clonedRow.find( '.wc-geolocation-based-products-remove-row' ).prop( 'checked', false );
     100                clonedRow.find( '.wc-geolocation-based-products-test' ).prop( 'checked', false );
    79101
    80102                // remove country field value
    81103                clonedRow.find( '.wc-geolocation-based-products-country' ).val( '' );
     104
     105                // remove region field value
     106                clonedRow.find( '.wc-geolocation-based-products-region' ).val( '' );
     107
     108                // remove city field value
     109                clonedRow.find( '.wc-geolocation-based-products-city' ).val( '' );
    82110
    83111                // append row to table
     
    107135                        // remove checkmark
    108136                        table.find( '.wc-geolocation-based-products-remove-row' ).prop( 'checked', false );
     137                        table.find( '.wc-geolocation-based-products-test' ).prop( 'checked', false );
    109138
    110139                        // remove country field value
    111140                        table.find( '.wc-geolocation-based-products-country' ).val( '' );
     141
     142                        // remove region field value
     143                        table.find( '.wc-geolocation-based-products-region' ).val( '' );
     144
     145                        // remove city field value
     146                        table.find( '.wc-geolocation-based-products-city' ).val( '' );
    112147
    113148                        // reset select options
     
    124159                $.wc_geolocation_based_products_admin.reInitRows();
    125160            });
     161
     162            // test checkbox toggles
     163            $( 'table.wc-geolocation-based-products-settings' ).on( 'click', '.wc-geolocation-based-products-test', function() {
     164                // remove checkmark from all
     165                $( this ).parents( 'table.wc-geolocation-based-products-settings' ).find( '.wc-geolocation-based-products-test' ).not( this ).prop( 'checked', false );
     166
     167                return true;
     168            });
    126169        }
    127170    }; // close namespace
  • woocommerce-geolocation-based-products/trunk/plugin-assets/js/admin-settings.min.js

    r948488 r958980  
    1 jQuery(document).ready(function(e){"use strict";e.wc_geolocation_based_products_admin={runChosen:function(){e("select.wc-geolocation-based-products-choose-products").each(function(){e(this).ajaxChosen({method:"GET",url:wc_geolocation_based_products_local.ajaxURL,dataType:"json",afterTypeDelay:100,data:{action:"wc_geolocation_based_products_search_products_ajax",security:wc_geolocation_based_products_local.ajaxProductSearchNonce}},function(t){var n={};e.each(t,function(e,t){n[e]=t});return n}).next(".chosen-container").eq(0).css("width","100%");e(this).next(".chosen-container").find(".search-field input").css("width","auto")});e("select.wc-geolocation-based-products-choose-product-categories").each(function(){e(this).chosen({allow_single_deselect:"true",width:"100%"})})},reInitRows:function(){e("table.wc-geolocation-based-products-settings").find("tr.entry").each(function(t){var n=String(e("input.wc-geolocation-based-products-country",this).prop("name")),r=n.replace(/row\[\d+\]/,"row["+t+"]");e("input.wc-geolocation-based-products-country",this).prop("name",r);n=String(e("select.wc-geolocation-based-products-choose-products",this).prop("name"));r=n.replace(/row\[\d+\]/,"row["+t+"]");e("select.wc-geolocation-based-products-choose-products",this).prop("name",r);n=String(e("select.wc-geolocation-based-products-choose-product-categories",this).prop("name"));r=n.replace(/row\[\d+\]/,"row["+t+"]");e("select.wc-geolocation-based-products-choose-product-categories",this).prop("name",r)})},init:function(){e.wc_geolocation_based_products_admin.runChosen();e("table.wc-geolocation-based-products-settings").on("click",".insert-row",function(t){t.preventDefault();var n=e(this).parents("table.wc-geolocation-based-products-settings"),r=n.find("tr.entry").eq(0).clone();r.find("select.wc-geolocation-based-products-choose-products").css("display","block").val("").removeClass("chzn-done").next(".chosen-container").remove();r.find("select.wc-geolocation-based-products-choose-product-categories").css("display","block").val("").removeClass("chzn-done").next(".chosen-container").remove();r.find(".wc-geolocation-based-products-remove-row").prop("checked",false);r.find(".wc-geolocation-based-products-country").val("");n.find("tbody").append(r);e.wc_geolocation_based_products_admin.runChosen();e.wc_geolocation_based_products_admin.reInitRows();r.find("select.wc-geolocation-based-products-choose-product-categories option").prop("selected",false).parents("select.wc-geolocation-based-products-choose-product-categories").trigger("chosen:updated");r.find("select.wc-geolocation-based-products-choose-products option").prop("selected",false).parents("select.wc-geolocation-based-products-choose-products").trigger("chosen:updated")});e("table.wc-geolocation-based-products-settings").on("click",".remove-row",function(t){t.preventDefault();var n=e(this).parents("table.wc-geolocation-based-products-settings");n.find(".wc-geolocation-based-products-remove-row:checked").each(function(){if(n.find("tr.entry").length===1){n.find(".wc-geolocation-based-products-remove-row").prop("checked",false);n.find(".wc-geolocation-based-products-country").val("");n.find("select.wc-geolocation-based-products-choose-products").val("").trigger("chosen:updated");n.find("select.wc-geolocation-based-products-choose-product-categories").val("").trigger("chosen:updated")}else{e(this).parents("tr.entry").eq(0).remove()}});e.wc_geolocation_based_products_admin.reInitRows()})}};e.wc_geolocation_based_products_admin.init()})
     1jQuery(document).ready(function(e){"use strict";e.wc_geolocation_based_products_admin={runChosen:function(){e("select.wc-geolocation-based-products-choose-products").each(function(){e(this).ajaxChosen({method:"GET",url:wc_geolocation_based_products_local.ajaxURL,dataType:"json",afterTypeDelay:100,data:{action:"wc_geolocation_based_products_search_products_ajax",security:wc_geolocation_based_products_local.ajaxProductSearchNonce}},function(t){var n={};e.each(t,function(e,t){n[e]=t});return n}).next(".chosen-container").eq(0).css("width","100%");e(this).next(".chosen-container").find(".search-field input").css("width","auto")});e("select.wc-geolocation-based-products-choose-product-categories").each(function(){e(this).chosen({allow_single_deselect:"true",width:"100%"})})},reInitRows:function(){e("table.wc-geolocation-based-products-settings").find("tr.entry").each(function(t){var n=String(e("input.wc-geolocation-based-products-country",this).prop("name")),r=n.replace(/row\[\d+\]/,"row["+t+"]");e("input.wc-geolocation-based-products-country",this).prop("name",r);n=String(e("input.wc-geolocation-based-products-region",this).prop("name"));r=n.replace(/row\[\d+\]/,"row["+t+"]");e("input.wc-geolocation-based-products-region",this).prop("name",r);n=String(e("input.wc-geolocation-based-products-city",this).prop("name"));r=n.replace(/row\[\d+\]/,"row["+t+"]");e("input.wc-geolocation-based-products-city",this).prop("name",r);n=String(e("select.wc-geolocation-based-products-choose-products",this).prop("name"));r=n.replace(/row\[\d+\]/,"row["+t+"]");e("select.wc-geolocation-based-products-choose-products",this).prop("name",r);n=String(e("select.wc-geolocation-based-products-choose-product-categories",this).prop("name"));r=n.replace(/row\[\d+\]/,"row["+t+"]");e("select.wc-geolocation-based-products-choose-product-categories",this).prop("name",r);n=String(e("input.wc-geolocation-based-products-test",this).prop("name"));r=n.replace(/row\[\d+\]/,"row["+t+"]");e("input.wc-geolocation-based-products-test",this).prop("name",r)})},init:function(){e.wc_geolocation_based_products_admin.runChosen();e("table.wc-geolocation-based-products-settings").on("click",".insert-row",function(t){t.preventDefault();var n=e(this).parents("table.wc-geolocation-based-products-settings"),r=n.find("tr.entry").eq(0).clone();r.find("select.wc-geolocation-based-products-choose-products").css("display","block").val("").removeClass("chzn-done").next(".chosen-container").remove();r.find("select.wc-geolocation-based-products-choose-product-categories").css("display","block").val("").removeClass("chzn-done").next(".chosen-container").remove();r.find(".wc-geolocation-based-products-remove-row").prop("checked",false);r.find(".wc-geolocation-based-products-test").prop("checked",false);r.find(".wc-geolocation-based-products-country").val("");r.find(".wc-geolocation-based-products-region").val("");r.find(".wc-geolocation-based-products-city").val("");n.find("tbody").append(r);e.wc_geolocation_based_products_admin.runChosen();e.wc_geolocation_based_products_admin.reInitRows();r.find("select.wc-geolocation-based-products-choose-product-categories option").prop("selected",false).parents("select.wc-geolocation-based-products-choose-product-categories").trigger("chosen:updated");r.find("select.wc-geolocation-based-products-choose-products option").prop("selected",false).parents("select.wc-geolocation-based-products-choose-products").trigger("chosen:updated")});e("table.wc-geolocation-based-products-settings").on("click",".remove-row",function(t){t.preventDefault();var n=e(this).parents("table.wc-geolocation-based-products-settings");n.find(".wc-geolocation-based-products-remove-row:checked").each(function(){if(n.find("tr.entry").length===1){n.find(".wc-geolocation-based-products-remove-row").prop("checked",false);n.find(".wc-geolocation-based-products-test").prop("checked",false);n.find(".wc-geolocation-based-products-country").val("");n.find(".wc-geolocation-based-products-region").val("");n.find(".wc-geolocation-based-products-city").val("");n.find("select.wc-geolocation-based-products-choose-products").val("").trigger("chosen:updated");n.find("select.wc-geolocation-based-products-choose-product-categories").val("").trigger("chosen:updated")}else{e(this).parents("tr.entry").eq(0).remove()}});e.wc_geolocation_based_products_admin.reInitRows()});e("table.wc-geolocation-based-products-settings").on("click",".wc-geolocation-based-products-test",function(){e(this).parents("table.wc-geolocation-based-products-settings").find(".wc-geolocation-based-products-test").not(this).prop("checked",false);return true})}};e.wc_geolocation_based_products_admin.init()})
  • woocommerce-geolocation-based-products/trunk/readme.txt

    r948488 r958980  
    55Tested up to: 3.9.1
    66WooCommerce requires at least: 2.1.12
    7 Stable tag: 1.0.0
     7Stable tag: 1.1.0
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2626You can add many different countries in which you want the settings to apply to.  You do this by adding a row and setting the 2 letter country code in which you want to apply to.  For example "US".  Then you set whether you want to hide certain product categories or just products themselves.  You may select more than one for each.
    2727
    28 You can also use the country test simulator to test out your settings as if you're visiting the site from another country.  Please note that you will need to use this especially when you're testing this on localhost as that IP will not be valid.  Be sure to remove this country code when done testing and ready to go live.
     28You can also add a region.  For example if I want to target anyone that is in the US and in California, I would enter the region code of CA for California. 
     29
     30Furthermore, you can also filter by city.  For example if I want to target anyone that is in the US and California but also in the city of Los Angeles, I would enter the city name Los Angeles in the field.
     31
     32You can also test out your settings as if you're visiting the site from another country.  Enabling the testmode on a particular entry row, your site will hide/show the products/categories per the rules of that row.  Please note that you will need to use this especially when you're testing this on localhost as that IP will not be valid.  Be sure to turn off testmode when done testing and ready to go live.
    2933
    3034== Frequently Asked Questions ==
     
    4044== Changelog ==
    4145
     46= 1.1.0 =
     47Added - Ability to geolocate by region
     48Added - Ability to geolocate by city
     49Update - Test mode is now against each individual row of settings
     50
    4251= 1.0.0 =
    4352Release
  • woocommerce-geolocation-based-products/trunk/woocommerce-geolocation-based-products.php

    r948488 r958980  
    44Plugin URI: http://splashingpixels.com/
    55Description: A WooCommerce plugin/extension that adds ability for your store to show/hide products based on visitors geolocation.
    6 Version: 1.0.0
     6Version: 1.1.0
    77Author: SplashingPixels / Roy Ho
    88
     
    3434     * @return bool
    3535     */
    36     function __construct() {
     36    public function __construct() {
    3737       
    3838        add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
Note: See TracChangeset for help on using the changeset viewer.