Home Forums General Issues How to receive wc customer acf in order export


How to receive wc customer acf in order export

  • Hi

    I use Woocommerce (WC) with WP-All-Import + WP-All-Export and ACF.

    I added a ACF field CustomerNumber to the WC-Customer (which enhanced the WP-User).
    On the XML-Import I set the CustomerNumber with a value from a ERP.
    So all customers have these CustomerNumber.

    I now need to export the WC-Orders (to import them in the ERP again).
    The Order-XML must include the CustomerNumber from the Customer belongs to the Order.

    As I see, the other standard fields from the customer – like name and address – are copied automatically to the order (by woocommerce itself).

    My question is now: How I have to do this for the ACF’s?
    Did I have to do this by code on my own? Adding the same AC-fields to the WC-Order and hook into the order checkout and copy the values from the customer to the order?
    Or is there some kind of setup which do that and which I did not recognize?


  • I solved it for my needs.

    I also added this acf for the orders.
    And on a new order I copy the customer acf value to the order acf.

    function my_new_order( $order_id ) {
    	$order = new WC_Order( $order_id );
    	if ( !$order ) return;
    	$customer_id = $order->get_customer_id();
    	if ( !$customer_id ) return;
    	$customer = new WC_Customer($customer_id);
    	if ( !$customer ) return;
    	$customer_number = $customer->get_meta('customernumber');
    	if ( !$customer_number ) return;
    	$order->add_meta_data('customernumber', $customer_number);
    	$res = $order->save_meta_data();
    add_action( 'woocommerce_checkout_order_processed', 'my_new_order', 10, 1);
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to receive wc customer acf in order export’ is closed to new replies.