Okay
  Public Ticket #2975328
customization
Closed

Comments

  •  7
    CANDY started the conversation

    I am not sure if this is in the realm of our support but here is my question. I have created a custom registration field for customers of "customer id" this correlates to the customers id (main identifier) in our accounting software. Do you know how I would code woocommerce to show this on the sales order?. Ideally we would want it to show with the other customer information.  This is information generally the customer would not know. we manually input the data when approving a new b2b customer,.

  •  2,218
    WebWizards replied

    Hi there,

    You can add the following PHP code snippet to your site:

    add_action('woocommerce_admin_order_data_after_billing_address', function(){
        $customer_id = 'TEST';
        if (!empty($customer_id)){
            ?>
            <p class="form-field form-field-wide"><strong>Customer ID (internal):</strong>
            <?php
            echo $customer_id;
            ?>
            </p>
            <?php
        }
    });
    

    It will look like this in the order details page:

    7074647044.png


    You would need to change "$customer_id = 'TEST'" with your actual data. I don't really know how or where this is stored in your case. If it's stored as user meta data, you can get it with something like this: $customer_id = get_user_meta($user_id, 'meta_key', true);


    If this customer ID is a b2bking field, then the meta key will probably be "b2bking_custom_field_1234" where 1234 is the field ID. It can be checked in the wp_usermeta table if you have experience with that sort of thing.


    Let me know if that helps,

    Kind regards,

    Stefan

  •  7
    CANDY replied

    thank you i will give that a try. and yes the field is a b2bking custom registration field

  •  7
    CANDY replied

    ok dumb question, where would I add the code on the site?   MY BAD.. figured it out do in snippets.

  •  7
    CANDY replied

    I cant seem to get this working.

     the test one works, when i try the data one. nothing shows. code i am using is

    add_action('woocommerce_admin_order_data_after_billing_address', function(){
        $customer_id = get_user_meta($user_id, 'b2bking_custom_field_9926', true);
        if (!empty($customer_id)){
            ?>
            <p class="form-field form-field-wide"><strong>Customer ID (internal):</strong>
            <?php
            echo $customer_id;
            ?>
            </p>
            <?php
        }
    });


  •  2,218
    WebWizards replied

    Hi there,

    Please try to replace your current snippet, with the following:

    add_action('woocommerce_admin_order_data_after_billing_address', function($order){
        $user_id = $order->get_customer_id();
        $customer_data = get_user_meta($user_id, 'b2bking_custom_field_9926', true);
        if (!empty($customer_data)){
            ?>
            <p class="form-field form-field-wide"><strong>Customer ID (internal):</strong>
            <?php
            echo $customer_data;
            ?>
            </p>
            <?php
        }
    }, 10, 1);
    

    If that doesn't work, would it be possible for you to share a backend login to your site or staging site so we can check directly? Or if you have any error, please send us the error.


    Kind regards,

    Stefan

  •  7
    CANDY replied

    yes that one worked. thank you so much!!!