php - Hide address if already completed WooCommerce -


i'm looking way hide billing address on checkout page of woocommerce theme if user has filled billing form (from previous order or if user has done "my account" page).

i've found ways hide billing / shipping form on checkout page if user logged in (see below), can't find way above.

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); function custom_override_checkout_fields( $fields ) {     if( is_user_logged_in() ){         unset($fields['billing']);         $fields['billing'] = array();     }     return $fields; } 

any idea?

thank you!

it depend consider completed address made snippet function can use go further with.

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); function custom_override_checkout_fields( $fields ) {     if( is_user_logged_in() && !has_billing()){         unset($fields['billing']);         $fields['billing'] = array();     }     return $fields; }  // check meta of postcode , country if entered. function has_billing($user_id = false){             if(!$user_id)                 $user_id = get_current_user_id();              $shipping_postcode = get_user_meta( $user_id, 'billing_postcode', true );             $shipping_country = get_user_meta( $user_id, 'billing_country', true );              // fetch more meta condition has needed.               if($shipping_postcode && $shipping_country){                 return true;             }              return false; } 

note: prefix shipping_ there 1 billing ( billing_ ).

edit: here meta key billing_address_1 , billing_address_2 prefix can either billing_ or shipping_

also if reason don't have shipping or billing address associated in user meta keys customer once did order can check code fetch order address.

woocommerce wc_order get_shipping_address() not returning array (old post might not valid anymore)


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -