Changeset 2663679
- Timestamp:
- 01/24/2022 04:32:18 PM (4 years ago)
- Location:
- woo-address-book/trunk
- Files:
-
- 5 edited
-
assets/js/scripts.js (modified) (2 diffs)
-
assets/js/scripts.min.js (modified) (1 diff)
-
includes/class-wc-address-book.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
-
woocommerce-address-book.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-address-book/trunk/assets/js/scripts.js
r2639316 r2663679 144 144 * AJAX call display address on checkout when selected. 145 145 */ 146 function checkout_field_prepop( addressType ) {146 function checkout_field_prepop( addressType ) { 147 147 148 148 let countryInputName = addressType + '_country'; 149 let stateInputName = addressType + '_state';150 151 let countryInput = $( '#' + countryInputName );152 let stateInput = $( '#' + stateInputName );153 149 154 150 let that = $( '#' + addressType + '_address_book_field #' + addressType + '_address_book' ); 155 151 let name = $( that ).val(); 156 152 157 if ( name !== undefined ) {153 if ( name !== undefined && name !== null ) { 158 154 159 155 if ( 'add_new' === name ) { 160 156 161 157 // Clear values when adding a new address. 162 $( '.woocommerce-' + addressType + '-fields__field-wrapper input' ).not( $( '#' + countryInputName ) ).each( function () { 163 $( this ).val( '' ); 158 $( '.woocommerce-' + addressType + '-fields__field-wrapper input' ).not( $( '#' + countryInputName ) ).not( '#' + addressType + '_address_book' ).each( function () { 159 var input = $( this ); 160 if ( input.attr("type") === "checkbox" || input.attr("type") === "radio") { 161 input.prop( "checked", false ); 162 } else { 163 input.val( '' ); 164 } 164 165 } ); 165 166 // Set Country Dropdown. 167 // Don't reset the value if only one country is available to choose. 168 if ( countryInput.length > 0 && countryInput.attr( 'readonly' ) !== 'readonly' ) { 169 countryInput.val( [] ).trigger( 'change' ); 170 $( '#' + countryInputName + '_chosen' ).find( 'span' ).html( '' ); 171 } 172 173 // Set state dropdown. 174 if ( stateInput.length > 0 && stateInput.attr( 'readonly' ) !== 'readonly' ) { 175 stateInput.val( [] ).trigger( 'change' ); 176 $( '#' + stateInputName + '_chosen' ).find( 'span' ).html( '' ); 166 $( '.woocommerce-' + addressType + '-fields__field-wrapper select' ).not( $( '#' + countryInputName ) ).not( '#' + addressType + '_address_book' ).each( function () { 167 var input = $( this ); 168 if ( input.hasClass( 'selectized' ) && input[0] && input[0].selectize ) { 169 input[0].selectize.setValue( "" ); 170 } else { 171 input.val( [] ).trigger( 'change' ); 172 } 173 } ); 174 175 // If shipping calculator used on cart page 176 if ( addressType === 'shipping' && typeof shipping_country_o !== 'undefined' && typeof shipping_state_o !== 'undefined' && typeof shipping_city_o !== 'undefined' && typeof shipping_postcode_o !== 'undefined' ) { 177 178 $( "#shipping_country" ).val( shipping_country_o ).trigger( 'change' ); 179 $( "#shipping_state" ).val( shipping_state_o ).trigger( 'change' ); 180 $( "#shipping_city" ).val( shipping_city_o ); 181 $( "#shipping_postcode" ).val( shipping_postcode_o ); 182 183 delete shipping_country_o; 184 delete shipping_state_o; 185 delete shipping_city_o; 186 delete shipping_postcode_o; 187 188 // Remove BlockUI overlay 189 $( '.woocommerce-shipping-fields' ).unblock(); 190 177 191 } 178 192 … … 196 210 dataType: 'json', 197 211 success: function ( response ) { 212 213 // If shipping calculator used on cart page 198 214 if ( addressType === 'shipping' && typeof shipping_country_o !== 'undefined' && typeof shipping_state_o !== 'undefined' && typeof shipping_city_o !== 'undefined' && typeof shipping_postcode_o !== 'undefined' ) { 199 215 // If entered values do not equal shipping calculator values 200 216 if ( shipping_country_o !== response.shipping_country || shipping_state_o !== response.shipping_state || shipping_city_o !== response.shipping_city || shipping_postcode_o !== response.shipping_postcode ) { 201 202 217 $( "#shipping_address_book" ).val( 'add_new' ).trigger( 'change' ); 203 204 $( "#shipping_country" ).val( shipping_country_o ).trigger( 'change' ); 205 $( "#shipping_state" ).val( shipping_state_o ).trigger( 'change' ); 206 $( "#shipping_city" ).val( shipping_city_o ); 207 $( "#shipping_postcode" ).val( shipping_postcode_o ); 218 return; 208 219 } 209 210 delete shipping_country_o;211 delete shipping_state_o;212 delete shipping_city_o;213 delete shipping_postcode_o;214 215 // Remove BlockUI overlay216 $( '.woocommerce-shipping-fields' ).unblock();217 218 return;219 220 } 220 221 221 // Loop through all fields incase there are custom ones.222 // Loop through all fields and set values to the form. 222 223 Object.keys( response ).forEach( function ( key ) { 223 224 let input = $( '#' + key ); 224 if ( input.length > 0 && input.attr( 'readonly' ) !== 'readonly' ) { 225 input.val( response[key] ).trigger( 'change' ); 225 if ( input.length > 0 ) { 226 if ( input.attr( 'readonly' ) !== 'readonly' ) { 227 if ( input.is("select") ) { 228 if ( input.hasClass( 'selectized' ) && input[0] && input[0].selectize ) { 229 input[0].selectize.setValue( response[key] ); 230 } else { 231 input.val( response[key] ).trigger( 'change' ); 232 } 233 } else if ( input.attr("type") === "checkbox" ) { 234 input.prop( 'checked', response[key] === "1" ).trigger( 'change' ); 235 } else { 236 input.val( response[key] ).trigger( 'change' ); 237 } 238 } 239 } else { 240 // Handle radio buttons. 241 let radio_field = $( '#' + key + '_field' ); 242 if ( radio_field.length > 0 ) { 243 radio_field.find("input[type='radio']").each( function (index, radio_button) { 244 if ( $(radio_button).val() === response[key] ) { 245 $(radio_button).prop( 'checked', true ).trigger( 'change' ); 246 } 247 }); 248 } 226 249 } 227 250 } ); 228 229 230 // Set Country Dropdown.231 if ( countryInput.length > 0 && countryInput.attr( 'readonly' ) !== 'readonly' ) {232 if ( countryInput.hasClass( 'selectized' ) && countryInput[0] && countryInput[0].selectize ) {233 countryInput[0].selectize.setValue( response[countryInputName] );234 } else {235 countryInput.val( response[countryInputName] ).trigger( 'change' );236 let countryInputNameText = countryInputName + '_text';237 $( '#' + countryInputName + '_chosen' ).find( 'span' ).html( response.countryInputNameText );238 }239 }240 241 // Set state dropdown.242 if ( stateInput.length > 0 && stateInput.attr( 'readonly' ) !== 'readonly' ) {243 if ( stateInput.hasClass( 'selectized' ) && stateInput[0] && stateInput[0].selectize ) {244 stateInput[0].selectize.setValue( response[stateInputName] );245 } else {246 stateInput.val( response[stateInputName] ).trigger( 'change' );247 let stateName = $( '#' + stateInputName + ' option[value="' + response[stateInputName] + '"]' ).text();248 $( '#s2id_' + stateInputName ).find( '.select2-chosen' ).html( stateName ).parent().removeClass( 'select2-default' );249 }250 }251 251 252 252 // Remove BlockUI overlay -
woo-address-book/trunk/assets/js/scripts.min.js
r2639316 r2663679 1 jQuery(function($){var load_selectWoo=true;var address_book=$("select#shipping_address_book:visible, select#billing_address_book:visible");if($.fn.selectize){if(address_book.hasClass("selectized")&&address_book[0]&&address_book[0].selectize){load_selectWoo=false}}if(load_selectWoo){if($.fn.selectWoo){address_book.selectWoo()}else if($.fn.select2){address_book.select2()}}$.blockUI.defaults.message=null;$.blockUI.defaults.overlayCSS.backgroundColor="#fff";checkout_field_prepop("billing");$("#billing_address_book_field #billing_address_book").on("change",function(){checkout_field_prepop("billing")});if($("form[name=checkout]").length>0&&($("#shipping_country").val()!==""||$("#shipping_state").val()!==""||$("#shipping_city").val()!==""||$("#shipping_postcode").val()!=="")){shipping_country_o=$("#shipping_country").val();shipping_state_o=$("#shipping_state").val();shipping_city_o=$("#shipping_city").val();shipping_postcode_o=$("#shipping_postcode").val()}checkout_field_prepop("shipping");$("#shipping_address_book_field #shipping_address_book").on("change",function(){checkout_field_prepop("shipping")});if($("form[name=checkout]").length>0){$("#shipping_country, #shipping_state_field, #shipping_city, #shipping_postcode, #billing_country, #billing_state_field, #billing_city, #billing_postcode").on("change",function(){$(document.body).trigger("update_checkout")})}$("a.wc-address-book-delete").on("click",function(e){e.preventDefault();var confirmDelete=confirm(woo_address_book.delete_confirmation);if(!confirmDelete){return}var name=$(this).attr("id");var toRemove=$(this).closest(".wc-address-book-address");$(".woocommerce-MyAccount-content").block();$.ajax({url:woo_address_book.ajax_url,type:"post",data:{action:"wc_address_book_delete",name:name,nonce:woo_address_book.delete_security},success:function(){toRemove.remove();$(".woocommerce-MyAccount-content").unblock()}})});$("a.wc-address-book-make-primary").on("click",function(e){e.preventDefault();var name=$(this).attr("id");var type=name.replace(/\d+/g,"");if(type==="billing"){var primary_address=$(".u-column1.woocommerce-Address address")}else if(type==="shipping"){var primary_address=$(".u-column2.woocommerce-Address address")}else{return}var alt_address=$(this).parent().siblings("address");var pa_html=primary_address.html();var aa_html=alt_address.html();$(".woocommerce-MyAccount-content").block();$.ajax({url:woo_address_book.ajax_url,type:"post",data:{action:"wc_address_book_make_primary",name:name,nonce:woo_address_book.primary_security},success:function(){alt_address.html(pa_html);primary_address.html(aa_html);$(".woocommerce-MyAccount-content").unblock()}})});function checkout_field_prepop(addressType){let countryInputName=addressType+"_country";let stateInputName=addressType+"_state";let countryInput=$("#"+countryInputName);let stateInput=$("#"+stateInputName);let that=$("#"+addressType+"_address_book_field #"+addressType+"_address_book");let name=$(that).val();if(name!==undefined){if("add_new"===name){$(".woocommerce-"+addressType+"-fields__field-wrapper input").not($("#"+countryInputName)).each(function(){$(this).val("")});if(countryInput.length>0&&countryInput.attr("readonly")!=="readonly"){countryInput.val([]).trigger("change");$("#"+countryInputName+"_chosen").find("span").html("")}if(stateInput.length>0&&stateInput.attr("readonly")!=="readonly"){stateInput.val([]).trigger("change");$("#"+stateInputName+"_chosen").find("span").html("")}return}if(name.length>0){$(".woocommerce-"+addressType+"-fields").block();$.ajax({url:woo_address_book.ajax_url,type:"post",data:{action:"wc_address_book_checkout_update",name:name,type:addressType,nonce:woo_address_book.checkout_security},dataType:"json",success:function(response){if(addressType==="shipping"&&typeof shipping_country_o!=="undefined"&&typeof shipping_state_o!=="undefined"&&typeof shipping_city_o!=="undefined"&&typeof shipping_postcode_o!=="undefined"){if(shipping_country_o!==response.shipping_country||shipping_state_o!==response.shipping_state||shipping_city_o!==response.shipping_city||shipping_postcode_o!==response.shipping_postcode){$("#shipping_address_book").val("add_new").trigger("change");$("#shipping_country").val(shipping_country_o).trigger("change");$("#shipping_state").val(shipping_state_o).trigger("change");$("#shipping_city").val(shipping_city_o);$("#shipping_postcode").val(shipping_postcode_o)}delete shipping_country_o;delete shipping_state_o;delete shipping_city_o;delete shipping_postcode_o;$(".woocommerce-shipping-fields").unblock();return}Object.keys(response).forEach(function(key){let input=$("#"+key);if(input.length>0&&input.attr("readonly")!=="readonly"){input.val(response[key]).trigger("change")}});if(countryInput.length>0&&countryInput.attr("readonly")!=="readonly"){if(countryInput.hasClass("selectized")&&countryInput[0]&&countryInput[0].selectize){countryInput[0].selectize.setValue(response[countryInputName])}else{countryInput.val(response[countryInputName]).trigger("change");let countryInputNameText=countryInputName+"_text";$("#"+countryInputName+"_chosen").find("span").html(response.countryInputNameText)}}if(stateInput.length>0&&stateInput.attr("readonly")!=="readonly"){if(stateInput.hasClass("selectized")&&stateInput[0]&&stateInput[0].selectize){stateInput[0].selectize.setValue(response[stateInputName])}else{stateInput.val(response[stateInputName]).trigger("change");let stateName=$("#"+stateInputName+' option[value="'+response[stateInputName]+'"]').text();$("#s2id_"+stateInputName).find(".select2-chosen").html(stateName).parent().removeClass("select2-default")}}$(".woocommerce-"+addressType+"-fields").unblock()}})}}}});1 jQuery(function($){var load_selectWoo=true;var address_book=$("select#shipping_address_book:visible, select#billing_address_book:visible");if($.fn.selectize){if(address_book.hasClass("selectized")&&address_book[0]&&address_book[0].selectize){load_selectWoo=false}}if(load_selectWoo){if($.fn.selectWoo){address_book.selectWoo()}else if($.fn.select2){address_book.select2()}}$.blockUI.defaults.message=null;$.blockUI.defaults.overlayCSS.backgroundColor="#fff";checkout_field_prepop("billing");$("#billing_address_book_field #billing_address_book").on("change",function(){checkout_field_prepop("billing")});if($("form[name=checkout]").length>0&&($("#shipping_country").val()!==""||$("#shipping_state").val()!==""||$("#shipping_city").val()!==""||$("#shipping_postcode").val()!=="")){shipping_country_o=$("#shipping_country").val();shipping_state_o=$("#shipping_state").val();shipping_city_o=$("#shipping_city").val();shipping_postcode_o=$("#shipping_postcode").val()}checkout_field_prepop("shipping");$("#shipping_address_book_field #shipping_address_book").on("change",function(){checkout_field_prepop("shipping")});if($("form[name=checkout]").length>0){$("#shipping_country, #shipping_state_field, #shipping_city, #shipping_postcode, #billing_country, #billing_state_field, #billing_city, #billing_postcode").on("change",function(){$(document.body).trigger("update_checkout")})}$("a.wc-address-book-delete").on("click",function(e){e.preventDefault();var confirmDelete=confirm(woo_address_book.delete_confirmation);if(!confirmDelete){return}var name=$(this).attr("id");var toRemove=$(this).closest(".wc-address-book-address");$(".woocommerce-MyAccount-content").block();$.ajax({url:woo_address_book.ajax_url,type:"post",data:{action:"wc_address_book_delete",name:name,nonce:woo_address_book.delete_security},success:function(){toRemove.remove();$(".woocommerce-MyAccount-content").unblock()}})});$("a.wc-address-book-make-primary").on("click",function(e){e.preventDefault();var name=$(this).attr("id");var type=name.replace(/\d+/g,"");if(type==="billing"){var primary_address=$(".u-column1.woocommerce-Address address")}else if(type==="shipping"){var primary_address=$(".u-column2.woocommerce-Address address")}else{return}var alt_address=$(this).parent().siblings("address");var pa_html=primary_address.html();var aa_html=alt_address.html();$(".woocommerce-MyAccount-content").block();$.ajax({url:woo_address_book.ajax_url,type:"post",data:{action:"wc_address_book_make_primary",name:name,nonce:woo_address_book.primary_security},success:function(){alt_address.html(pa_html);primary_address.html(aa_html);$(".woocommerce-MyAccount-content").unblock()}})});function checkout_field_prepop(addressType){let countryInputName=addressType+"_country";let that=$("#"+addressType+"_address_book_field #"+addressType+"_address_book");let name=$(that).val();if(name!==undefined&&name!==null){if("add_new"===name){$(".woocommerce-"+addressType+"-fields__field-wrapper input").not($("#"+countryInputName)).not("#"+addressType+"_address_book").each(function(){var input=$(this);if(input.attr("type")==="checkbox"||input.attr("type")==="radio"){input.prop("checked",false)}else{input.val("")}});$(".woocommerce-"+addressType+"-fields__field-wrapper select").not($("#"+countryInputName)).not("#"+addressType+"_address_book").each(function(){var input=$(this);if(input.hasClass("selectized")&&input[0]&&input[0].selectize){input[0].selectize.setValue("")}else{input.val([]).trigger("change")}});if(addressType==="shipping"&&typeof shipping_country_o!=="undefined"&&typeof shipping_state_o!=="undefined"&&typeof shipping_city_o!=="undefined"&&typeof shipping_postcode_o!=="undefined"){$("#shipping_country").val(shipping_country_o).trigger("change");$("#shipping_state").val(shipping_state_o).trigger("change");$("#shipping_city").val(shipping_city_o);$("#shipping_postcode").val(shipping_postcode_o);delete shipping_country_o;delete shipping_state_o;delete shipping_city_o;delete shipping_postcode_o;$(".woocommerce-shipping-fields").unblock()}return}if(name.length>0){$(".woocommerce-"+addressType+"-fields").block();$.ajax({url:woo_address_book.ajax_url,type:"post",data:{action:"wc_address_book_checkout_update",name:name,type:addressType,nonce:woo_address_book.checkout_security},dataType:"json",success:function(response){if(addressType==="shipping"&&typeof shipping_country_o!=="undefined"&&typeof shipping_state_o!=="undefined"&&typeof shipping_city_o!=="undefined"&&typeof shipping_postcode_o!=="undefined"){if(shipping_country_o!==response.shipping_country||shipping_state_o!==response.shipping_state||shipping_city_o!==response.shipping_city||shipping_postcode_o!==response.shipping_postcode){$("#shipping_address_book").val("add_new").trigger("change");return}}Object.keys(response).forEach(function(key){let input=$("#"+key);if(input.length>0){if(input.attr("readonly")!=="readonly"){if(input.is("select")){if(input.hasClass("selectized")&&input[0]&&input[0].selectize){input[0].selectize.setValue(response[key])}else{input.val(response[key]).trigger("change")}}else if(input.attr("type")==="checkbox"){input.prop("checked",response[key]==="1").trigger("change")}else{input.val(response[key]).trigger("change")}}}else{let radio_field=$("#"+key+"_field");if(radio_field.length>0){radio_field.find("input[type='radio']").each(function(index,radio_button){if($(radio_button).val()===response[key]){$(radio_button).prop("checked",true).trigger("change")}})}}});$(".woocommerce-"+addressType+"-fields").unblock()}})}}}}); -
woo-address-book/trunk/includes/class-wc-address-book.php
r2639316 r2663679 4 4 * 5 5 * @class WC_Address_Book 6 * @version 2.0. 06 * @version 2.0.1 7 7 * @package WooCommerce Address Book 8 8 */ … … 35 35 36 36 // Version Number. 37 $this->version = '2.0. 0';37 $this->version = '2.0.1'; 38 38 39 39 // Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively. … … 206 206 207 207 /** 208 * Format addresses from before update 1.8.0 where billing address functionality was added209 *210 * @param string $user_id The user ID.211 * @param string $type Address type.212 *213 * @since 1.8.0214 */215 public function format_addresses_backwards_compatible( $user_id, $type ) {216 $address_names = get_user_meta( $user_id, 'wc_address_book', true );217 218 $type_addresses = get_user_meta( $user_id, 'wc_address_book_' . $type, true );219 220 if ( empty( $type_addresses ) ) {221 if ( 'shipping' === $type ) {222 if ( is_array( $address_names ) ) {223 $this->save_address_names( $user_id, $address_names, 'shipping' );224 } elseif ( 'shipping' === $address_names ) {225 $this->save_address_names( $user_id, array( 'shipping' ), 'shipping' );226 }227 } elseif ( 'billing' === $type ) {228 $this->save_address_names( $user_id, array( 'billing' ), 'billing' );229 }230 }231 }232 233 /**234 208 * Get address type from name 235 209 * … … 527 501 528 502 $address_names = get_user_meta( $user_id, 'wc_address_book_' . $type, true ); 529 530 if ( empty( $address_names ) && 'shipping' === $type ) { 531 $this->format_addresses_backwards_compatible( $user_id, 'shipping' ); 532 533 $shipping_address = get_user_meta( $user_id, 'shipping_address_1', true ); 534 // Return just a default shipping address if no other addresses are saved. 535 if ( ! empty( $shipping_address ) ) { 536 return array( 'shipping' ); 537 } 538 // If we don't have a shipping address, just return an empty array. 503 if ( empty( $address_names ) ) { 504 if ( 'shipping' === $type ) { 505 // Check for shipping addresses saved in pre 2.0 format. 506 $address_names = get_user_meta( $user_id, 'wc_address_book', true ); 507 if ( is_array( $address_names ) ) { 508 // Save addresses in the new format. 509 $this->save_address_names( $user_id, $address_names, 'shipping' ); 510 return $address_names; 511 } 512 $shipping_address = get_user_meta( $user_id, 'shipping_address_1', true ); 513 // Return just a default shipping address if no other addresses are saved. 514 if ( ! empty( $shipping_address ) ) { 515 return array( 'shipping' ); 516 } 517 } 518 if ( 'billing' === $type ) { 519 $billing_address = get_user_meta( $user_id, 'billing_address_1', true ); 520 // Return just a default billing address if no other addresses are saved. 521 if ( ! empty( $billing_address ) ) { 522 return array( 'billing' ); 523 } 524 } 525 526 // If we don't have an address, just return an empty array. 539 527 return array(); 540 } elseif ( empty( $address_names ) && 'billing' === $type ) { 541 $this->format_addresses_backwards_compatible( $user_id, 'billing' ); 542 543 $billing_address = get_user_meta( $user_id, 'billing_address_1', true ); 544 // Return just a default billing address if no other addresses are saved. 545 if ( ! empty( $billing_address ) ) { 546 return array( 'billing' ); 547 } 548 // If we don't have a billing address, just return an empty array. 549 return array(); 550 } 528 } 529 551 530 return $address_names; 552 531 } -
woo-address-book/trunk/readme.txt
r2639316 r2663679 3 3 Tags: WooCommerce, address book, multiple addresses, address 4 4 Requires at least: 4.6 5 Tested up to: 5.8. 26 Stable tag: 2.0. 05 Tested up to: 5.8.3 6 Stable tag: 2.0.1 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 79 79 80 80 == Changelog == 81 82 = 2.0.1 = 83 * Fix select address issue when 'Add New Address as default selection' is enabled for shipping address. 84 * Improve backwards compatibility with versions prior to 2.0.0 85 * Better support custom field types other than standard input field. 81 86 82 87 = 2.0.0 = -
woo-address-book/trunk/woocommerce-address-book.php
r2639316 r2663679 3 3 * Plugin Name: WooCommerce Address Book 4 4 * Description: Gives your customers the option to store multiple shipping addresses and retrieve them on checkout.. 5 * Version: 2.0. 05 * Version: 2.0.1 6 6 * Author: Hall Internet Marketing 7 7 * Author URI: https://www.hallme.com/ … … 9 9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 * Text Domain: woo-address-book 11 * WC tested up to: 5.9.011 * WC tested up to: 6.1.1 12 12 * 13 13 * @package WooCommerce Address Book
Note: See TracChangeset
for help on using the changeset viewer.