• Resolved tylerw80

    (@tylerw80)


    We are trying to pull in data from a user profile custom field that we setup for our members.

    This is not custom order field data, we have that working OK.

    This is a custom field that we created for the actual user profile. So for each of our users we created a new field which is a special reference # for each of our users (long story, not going to explain it haha).

    In any case,

    How can we reference the right user and user profile custom field and pull it on to the pdf?

    Something like:

    $example = $wpo_wcpdf->export->order->user->special_ref

    Any help or guidance is very much appreciated

    https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi!
    Userdata is not always available, because by default WooCommerce lets people check out without creating an account to. The user object isn’t automatically loaded either, but you can do that from the _customer_user field in the order.

    Something like this should work:

    <?php
    $user_id = get_post_meta(this->order->id,'_customer_user');
    if ( !empty($user_id) && $user_id != 0 ) {
    	$special_ref = get_user_meta( $user_id, '_special_ref', true );
    	echo $special_ref;
    }
    ?>

    Or if you want to load the complete user object:

    <?php
    $user_id = get_post_meta($this->order->id,'_customer_user',true);
    if ( !empty($user_id) && $user_id != 0 ) {
    	$user = get_user_by( 'id', $user_id );
    	// do whatever you wish with the $user object here :)
    }
    ?>

    Hope that helps!
    Ewout

    Plugin Contributor Ewout

    (@pomegranate)

    Just noticed that there was a small error in the first snippet above. This should work:

    
    <?php
    $user_id = get_post_meta($this->order->id,'_customer_user',true);
    if ( !empty($user_id) && $user_id != 0 ) {
    	$special_ref = get_user_meta( $user_id, '_special_ref', true );
    	echo $special_ref;
    }
    ?>
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add User Profile Custom Data to PDF Invoice’ is closed to new replies.