Changeset 958980
- Timestamp:
- 08/01/2014 10:27:46 PM (12 years ago)
- Location:
- woocommerce-geolocation-based-products/trunk
- Files:
-
- 6 edited
-
includes/class-wc-geolocation-based-products-admin.php (modified) (12 diffs)
-
includes/class-wc-geolocation-based-products-frontend.php (modified) (10 diffs)
-
plugin-assets/js/admin-settings.js (modified) (6 diffs)
-
plugin-assets/js/admin-settings.min.js (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
-
woocommerce-geolocation-based-products.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-geolocation-based-products/trunk/includes/class-wc-geolocation-based-products-admin.php
r948488 r958980 88 88 $countrys = isset( $row['countrys'] ) ? strtoupper( sanitize_text_field( $row['countrys'] ) ) : ''; 89 89 90 $regions = isset( $row['regions'] ) ? strtoupper( sanitize_text_field( $row['regions'] ) ) : ''; 91 92 $cities = isset( $row['cities'] ) ? strtoupper( sanitize_text_field( $row['cities'] ) ) : ''; 93 90 94 if ( isset( $row['product_categories'] ) ) { 91 95 $product_categories = is_array( $row['product_categories'] ) ? array_map( 'absint', $row['product_categories'] ) : absint( $row[' product_categories'] ); … … 95 99 96 100 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'] ); 98 102 } else { 99 103 $products = array(); 100 104 } 101 105 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 102 112 $rows[] = array( 103 'countrys' => $countrys, 113 'countrys' => $countrys, 114 'regions' => $regions, 115 'cities' => $cities, 104 116 'product_categories' => $product_categories, 105 'products' => $products 117 'products' => $products, 118 'test' => $test 106 119 ); 107 120 } … … 109 122 // update options 110 123 update_option( 'wc_geolocation_based_products_settings', $rows ); 111 112 // test country113 $test_country = strtoupper( sanitize_text_field( $_POST['test_country'] ) );114 115 update_option( 'wc_geolocation_based_products_test_country', $test_country );116 124 } 117 125 … … 132 140 133 141 $cats = $this->get_product_categories(); 134 135 $test_country = get_option( 'wc_geolocation_based_products_test_country', false );136 142 ?> 137 143 <table class="wc-geolocation-based-products-settings widefat"> … … 140 146 <th><?php _e( 'Remove', 'woocommerce-geolocation-based-products' ); ?></th> 141 147 142 <th width="8%"><?php _e( 'Country Code', 'woocommerce-geolocation-based-products' ); ?> <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' ); ?> <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' ); ?> <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' ); ?> <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' ); ?> <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' ); ?> <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' ); ?> <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' ); ?> <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' ); ?> <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> 147 159 </tr> 148 160 </thead> … … 164 176 </td> 165 177 166 <td class="country" width=" 8%">178 <td class="country" width="5%"> 167 179 <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" /> 168 180 </td> 169 181 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%"> 171 191 <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' ); ?>"> 172 192 <option value=""></option> … … 183 203 </td> 184 204 185 <td class="products" width=" 45%">205 <td class="products" width="30%"> 186 206 <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' ); ?>"> 187 207 <option value=""></option> 188 208 </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" /> 189 213 </td> 190 214 </tr> … … 196 220 197 221 $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'] : ''; 198 228 ?> 199 229 <tr class="entry"> … … 202 232 </td> 203 233 204 <td class="country" width=" 8%">234 <td class="country" width="5%"> 205 235 <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" /> 206 236 </td> 207 237 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%"> 209 247 <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' ); ?>"> 210 248 <option value=""></option> … … 222 260 </td> 223 261 224 <td class="products" width=" 45%">262 <td class="products" width="30%"> 225 263 <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' ); ?>"> 226 264 <option value=""></option> … … 241 279 </select> 242 280 </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> 243 285 </tr> 244 286 <?php … … 249 291 </tbody> 250 292 </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>256 293 <?php 257 294 } -
woocommerce-geolocation-based-products/trunk/includes/class-wc-geolocation-based-products-frontend.php
r948488 r958980 5 5 6 6 class WC_Geolocation_Based_Products_Frontend { 7 8 var $location_data; 9 var $exclusion; 10 7 11 /** 8 12 * init … … 15 19 16 20 add_action( 'pre_get_posts', array( $this, 'filter_query' ) ); 17 18 add_filter( 'wc_geolocation_based_products_user_country', array( $this, 'filter_user_country' ) );19 21 20 22 // hide from category view 21 23 add_filter( 'woocommerce_product_subcategories_args', array( $this, 'hide_categories_view' ) ); 22 24 25 $this->location_data = $this->get_location_data(); 26 27 $this->exclusion = $this->get_exclusion(); 28 23 29 return true; 24 30 } … … 32 38 */ 33 39 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'] ); 37 41 38 42 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; 39 69 } 40 70 … … 52 82 53 83 $products = array(); 54 55 $user_country = $this->get_user_country();56 84 57 85 $rows = get_option( 'wc_geolocation_based_products_settings', false ); … … 60 88 // loop through the rows and get data 61 89 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' ) { 64 94 $exclude = true; 65 95 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 ) { 66 120 $product_cats = $row['product_categories']; 67 121 68 $products = $row['products']; 122 $products = $row['products']; 123 124 break; // after a match no need to look at the rest 69 125 } 70 126 } … … 73 129 if ( $exclude ) { 74 130 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; 75 233 } else { 76 234 return false; … … 92 250 } 93 251 94 $exclusion = $this->get_exclusion(); 95 96 if ( $exclusion ) { 252 if ( $this->exclusion ) { 97 253 $taxquery = array( 98 254 array( 99 255 'taxonomy' => 'product_cat', 100 256 'field' => 'id', 101 'terms' => $ exclusion['product_cats'],257 'terms' => $this->exclusion['product_cats'], 102 258 'operator' => 'NOT IN' 103 259 ) … … 106 262 $q->set( 'tax_query', $taxquery ); 107 263 108 $q->set( 'post__not_in', $ exclusion['products'] );264 $q->set( 'post__not_in', $this->exclusion['products'] ); 109 265 } else { 110 266 return; … … 120 276 */ 121 277 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'] ); 126 280 } 127 281 128 282 return $args; 129 }130 131 /**132 * filters the user country for testing133 *134 * @access public135 * @since 1.0.0136 * @param string137 * @return string $test_country138 */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 }147 283 } 148 284 … … 168 304 ) ); 169 305 170 $response = wp_remote_ get( $url, $args );306 $response = wp_remote_post( $url, $args ); 171 307 172 308 $response_body = @maybe_unserialize( wp_remote_retrieve_body( $response ) ); -
woocommerce-geolocation-based-products/trunk/plugin-assets/js/admin-settings.js
r948488 r958980 42 42 // re-init row positions 43 43 $( 'table.wc-geolocation-based-products-settings' ).find( 'tr.entry' ).each( function( row ) { 44 // reinit row position country 44 45 var rowPos = String( $( 'input.wc-geolocation-based-products-country', this ).prop( 'name' ) ), 45 46 replacedName = rowPos.replace( /row\[\d+\]/, 'row[' + row + ']' ); … … 47 48 $( 'input.wc-geolocation-based-products-country', this ).prop( 'name', replacedName ); 48 49 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 49 63 rowPos = String( $( 'select.wc-geolocation-based-products-choose-products', this ).prop( 'name' ) ); 50 64 replacedName = rowPos.replace( /row\[\d+\]/, 'row[' + row + ']' ); … … 52 66 $( 'select.wc-geolocation-based-products-choose-products', this ).prop( 'name', replacedName ); 53 67 68 // reinit row position product categories 54 69 rowPos = String( $( 'select.wc-geolocation-based-products-choose-product-categories', this ).prop( 'name' ) ); 55 70 replacedName = rowPos.replace( /row\[\d+\]/, 'row[' + row + ']' ); 56 71 57 72 $( '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 ); 58 79 }); 59 80 }, … … 77 98 // remove any checkmark 78 99 clonedRow.find( '.wc-geolocation-based-products-remove-row' ).prop( 'checked', false ); 100 clonedRow.find( '.wc-geolocation-based-products-test' ).prop( 'checked', false ); 79 101 80 102 // remove country field value 81 103 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( '' ); 82 110 83 111 // append row to table … … 107 135 // remove checkmark 108 136 table.find( '.wc-geolocation-based-products-remove-row' ).prop( 'checked', false ); 137 table.find( '.wc-geolocation-based-products-test' ).prop( 'checked', false ); 109 138 110 139 // remove country field value 111 140 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( '' ); 112 147 113 148 // reset select options … … 124 159 $.wc_geolocation_based_products_admin.reInitRows(); 125 160 }); 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 }); 126 169 } 127 170 }; // 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()})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("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 5 5 Tested up to: 3.9.1 6 6 WooCommerce requires at least: 2.1.12 7 Stable tag: 1. 0.07 Stable tag: 1.1.0 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 26 26 You 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. 27 27 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. 28 You 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 30 Furthermore, 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 32 You 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. 29 33 30 34 == Frequently Asked Questions == … … 40 44 == Changelog == 41 45 46 = 1.1.0 = 47 Added - Ability to geolocate by region 48 Added - Ability to geolocate by city 49 Update - Test mode is now against each individual row of settings 50 42 51 = 1.0.0 = 43 52 Release -
woocommerce-geolocation-based-products/trunk/woocommerce-geolocation-based-products.php
r948488 r958980 4 4 Plugin URI: http://splashingpixels.com/ 5 5 Description: A WooCommerce plugin/extension that adds ability for your store to show/hide products based on visitors geolocation. 6 Version: 1. 0.06 Version: 1.1.0 7 7 Author: SplashingPixels / Roy Ho 8 8 … … 34 34 * @return bool 35 35 */ 36 function __construct() {36 public function __construct() { 37 37 38 38 add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
Note: See TracChangeset
for help on using the changeset viewer.