programing

WooCommerce에서 프로그래밍 방식으로 고객 과금 정보 업데이트

telebox 2023. 3. 28. 21:34
반응형

WooCommerce에서 프로그래밍 방식으로 고객 과금 정보 업데이트

사용자가 이벤트에 등록하는 양식을 가지고 있으며, 사용자가 원하는 경우 청구 정보 중 일부를 즉시 업데이트할 수 있습니다.

예를 들어 업데이트할 수 있는 정보 목록이 있습니다.

 $inputs = array(
        'billing_city'          => 'City',
        'billing_postcode'      => 'Postcode',
        'billing_email'         =>  'Email',
        'billing_phone'         =>  'Phone',
    );

그 후, 저는 이 기능을WC_Customerclass를 클릭하여 변경된 정보를 업데이트합니다.

$customer = new WC_Customer( get_current_user_id() );
foreach ($inputs as $key => $label ) {
     $method = 'set_'. $key;
     $customer->$method( $value );
}

그것은 충분히 직설적으로 보일 것이다.단, 과금 정보는 변경되지 않습니다.

내가 뭘 잘못하고 있지?이 문제에 대처해야 할 다른 기능이 있습니까?

Woocommerce 문서로는 별로 설명이 되지 않습니다.

다음과 같이 함수를 사용하여 수행할 수 있습니다.

$user_id =  get_current_user_id();

$data = array(
    'billing_city'          => $city_value,
    'billing_postcode'      => $postcode_value,
    'billing_email'         => $email_value,
    'billing_phone'         => $phone_value,
);
foreach ($data as $meta_key => $meta_value ) {
    update_user_meta( $user_id, $meta_key, $meta_value );
}

어레이에서 값을 설정해야 합니다.

속성을 설정한 후 변경 내용을 저장해야 합니다.코드에서 Foreach 뒤에 다음을 추가합니다.

$customer->save();

그리고 부아!

언급URL : https://stackoverflow.com/questions/45940696/updating-programmatically-customers-billing-information-in-woocommerce

반응형