• Resolved thetrew

    (@thetrew)


    Hi. I would like to know how to add the customer name into the info section of my receipts. I have looked at the examples to edit the functions file in my child theme and have managed to get this far:

    // Print Customer Surname on Receipts
    function customer_name_order_fields( $fields, $order ) {
        $new_fields = array();
            
        if( get_post_meta( $order->get_ID(), 'billing_last_name', true ) ) {
            $new_fields['billing_last_name'] = array( 
                'label' => 'Customer Surname',
                'value' => get_post_meta( $order->get_ID(), 'billing_last_name', true )
            );
        }
        
        
        return array_merge( $fields, $new_fields );
    }
    add_filter( 'wcdn_order_info_fields', 'example_custom_order_fields', 10, 2 );

    …I used this example to see if I could start with getting just the surname, but even that didn’t work. I wondered if anyone might be a lot more clever than me :0)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support kenil802

    (@kenil802)

    Hi @thetrew,

    Sorry for the delay in response.

    I will ask the developer regarding your query and get back to you with an update.

    Regards,
    Kenil Shah

    Plugin Support kenil802

    (@kenil802)

    Hi @thetrew,

    Sorry for the delay in response.

    Please add the below code to add the surname in the info section.

    Code:

    function example_custom_order_fields( $fields, $order ) {
    $new_fields = array();
    $last = $order->get_billing_last_name();
    if( $last ) {
    $new_fields[‘billing_last_name’] = array(
    ‘label’ => ‘Customer Surname’,
    ‘value’ => $last,
    );
    }
    return array_merge( $fields, $new_fields );
    }
    add_filter( ‘wcdn_order_info_fields’, ‘example_custom_order_fields’, 10, 2 );

    I think the function name which was used was incorrect. So, please try the above code and see whether it works or not.

    Please let us know how it goes.

    Regards,
    Kenil Shah

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add customer full name to receipt’ is closed to new replies.