• Hello.

    I am using Advanced Custom Fields to add a custom field that is displayed on both the User’s profile and the Order information (meta data).

    I have created the field on ACF with the following info (please let me know if you need more details):

    Label: Sales Representative
    Field name: sales_representative
    Key: field_5ddfb34e47e47
    Type: User
    Return Format: User Array

    It seems to work fine on the website. I have registered on my customers’ accounts so I can see it on their profile pages. (I can add the code here but I’m guessing it’s irrelevant)

    Then, when a customer places an order, I get the Sales Representative from the user placing the order and add it to the order he is creating.

    // Add Sales Representative to Order
    function add_sales_representative_to_order_meta_data( $order, $data ) {
    
        $current_user_id = get_current_user_id();
        $sales_rep = get_field('sales_representative', 'user_'. $current_user_id );
    
        if( $sales_rep ) {
            if( $order->get_user_id() > 0 ) {
                $order->update_meta_data( 'sales_representative', $sales_rep );
            }
        }
    }
    add_action('woocommerce_checkout_create_order', 'add_sales_representative_to_order_meta_data', 10, 2 );

    When I open the order edit page, I can see the field there, of type User (I can change according to some rules set by ACF – For example, only users with Role “Sales Representative” show up on the list) so it seems to be working fine.

    I would guess there would be a “sales_representative” under “Setup fields to export” (and even “Filter by order”‘s “Custom fields” for that matter) but I can’t find it there. I have already selected “Reset Settings” but still it’s not there.

    What am I doing wrong here?

    Thank you for your help!

Viewing 15 replies - 1 through 15 (of 15 total)
Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Advanced Custom Fields PRO – Type User’ is closed to new replies.