• Resolved rasidrsd

    (@rasidrsd)


    Hey guys,

    I have searched my issue on the internet but was not able to fix it.

    I am trying to get custumer details from WooCommerce and print them on a pdf.
    The second part works perfectly fine via FPDF and FPDI.
    But i cant get the name, adress, order name, telephone number or email.

    Thats how it looks right now in my functions.php of my child theme:
    $order= new WC_Order($order_id);
    $name= $order->billing_first_name;
    $sur= $order->billing_last_name;
    $mail=$order->billing_email;

    All three variables are empty.
    Do I have to include/require something or what is the problem?

    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • A customer is a type of WordPress user. Try something like:

    // get the id of the customer
    $user_id = $order->post->post_author;
    // get the user object
    $user = get_user_by('id', $user_id);
    $firstname = $user->user_firstname;
    $lastname = $user->user_lastname;
    $email = $user->email;
    // get any user metadata required
    $billing_first_name = get_user_meta( $user_id, 'billing_first_name', true );
    
    Thread Starter rasidrsd

    (@rasidrsd)

    Thanks for the quick reply.
    But it still does not work :/ The variables are still empty.

    Yes, rubbish idea. Try:

    $billing_first_name = get_post_meta($order_id, '_billing_first_name', true );
    
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Getting Variables from Woocommerce’ is closed to new replies.