programing

WooCommerce: 배송 및 청구처 주소의 우편번호를 입수하여 설정

javamemo 2023. 3. 16. 21:06
반응형

WooCommerce: 배송 및 청구처 주소의 우편번호를 입수하여 설정

우편번호(Zip-code)를 woocommerce로 설정/취득하려면 어떻게 해야 하나요?이거 기능 있어요?

즉, 우편번호를 설정할 수 있는 기능이 있습니까?

또한 사용자가 로그인하지 않은 경우 이 필드에 데이터를 입력하는 방법(546621)도 알고 싶습니다.

다음을 수행하여 청구/배송 포스트코드를 입수/설정할 수 있습니다.

을 설정하려면

$customer = new WC_Customer();
$customer->set_postcode('123456');     //for setting billing postcode
$customer->set_shipping_postcode('123456');    //for setting shipping postcode

포스트 코드만 가져오려면 사용자 메타 테이블 자체에서 가져올 수 있습니다.

$shipping_postcode = get_user_meta( $current_user->ID, 'shipping_postcode', true );
$billing_postcode = get_user_meta( $current_user->ID, 'billing_postcode', true );

감사합니다 @rao!몇 시간 동안 이걸 찾았는데...코드를 가져와 사용자의 전체 주소를 가져올 수 있었습니다.그러면 각 주소 필드를 사용하여 다른 곳에서 만들고 있는 주소 양식에 미리 정보를 입력할 수 있습니다.

$fname = get_user_meta( $current_user->ID, 'first_name', true );
$lname = get_user_meta( $current_user->ID, 'last_name', true );
$address_1 = get_user_meta( $current_user->ID, 'billing_address_1', true ); 
$address_2 = get_user_meta( $current_user->ID, 'billing_address_2', true );
$city = get_user_meta( $current_user->ID, 'billing_city', true );
$postcode = get_user_meta( $current_user->ID, 'billing_postcode', true );

echo $fname . "<BR>";
echo $lname . "<BR>";
echo $address_1 . "<BR>";
echo $address_2 . "<BR>";
echo $city . "<BR>";
echo $postcode . "<BR>";

이 기능을 제공하는 WC_Customer 클래스를 사용할 수 있습니다.Woocommerce 클래스 내에 로드됩니다.이 정보는 현재 세션 내에 저장됩니다.

function set_shipping_zip() {
    global $woocommerce;

    //set it
    $woocommerce->customer->set_shipping_postcode( 12345 );
    $woocommerce->customer->set_postcode( 12345 );

    //get it
    $woocommerce->customer->get_shipping_postcode();    
    $woocommerce->customer->get_postcode();
}

이 클래스의 전체 매뉴얼은 http://docs.woothemes.com/wc-apidocs/class-WC_Customer.html

이게 도움이 됐으면 좋겠다.

언급URL : https://stackoverflow.com/questions/19155682/woocommerce-get-and-set-shipping-billing-addresss-postcode

반응형