woo-address-book icon indicating copy to clipboard operation
woo-address-book copied to clipboard

Limit the number of address

Open matt-h opened this issue 5 years ago • 1 comments

Add a way to set the number of addresses.

From here: https://wordpress.org/support/topic/limit-the-number-of-address/

matt-h avatar Jul 29 '20 14:07 matt-h

Hello, For creat a limit use this code and change the number "2" by the number you want !

add_filter('wc_address_book_show_shipping_address_button','limit_shipping_woo_book_address');
function limit_shipping_woo_book_address(){
	$wc_address_book = WC_Address_Book::get_instance();
	$woo_address_book_customer_id           = get_current_user_id();
	$woo_address_book_billing_address_book  = $wc_address_book->get_address_book( $woo_address_book_customer_id, 'billing' );
	$woo_address_book_shipping_address_book = $wc_address_book->get_address_book( $woo_address_book_customer_id, 'shipping' );
	$count_shipping = -1;
	foreach ( $woo_address_book_shipping_address_book as $woo_address_book_name => $woo_address_book_fields ) {
			$count_shipping++;	
	}
	if ($count_shipping < 2){ //change the number 2 by your limit desired
		return true;
	}else{
		return false;
	}
}
add_filter('wc_address_book_show_billing_address_button','limit_billing_woo_book_address');
function limit_billing_woo_book_address(){
	$wc_address_book = WC_Address_Book::get_instance();
	$woo_address_book_customer_id           = get_current_user_id();
	$woo_address_book_billing_address_book  = $wc_address_book->get_address_book( $woo_address_book_customer_id, 'billing' );
	$count_billing = 0;
	foreach ( $woo_address_book_billing_address_book as $woo_address_book_name => $woo_address_book_fields ) {
			$count_billing++;	
	}
	if ($count_billing < 2){ //change the number 2 by your limit desired
		return true;
	}else{
		return false;
	}
}

M1ckael avatar Apr 05 '22 05:04 M1ckael

A setting for this was added in version 2.3.0

matt-h avatar Feb 13 '23 21:02 matt-h