woo-address-book
woo-address-book copied to clipboard
Limit the number of address
Add a way to set the number of addresses.
From here: https://wordpress.org/support/topic/limit-the-number-of-address/
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;
}
}
A setting for this was added in version 2.3.0