Support » Plugin: WooCommerce PDF Invoices & Packing Slips » Display ACF of user on Packing Slip

  • Resolved seemorematt

    (@seemorematt)


    Hi,

    I am trying to display an advanced custom field on the packing slip by using the user id. I have no trouble getting the id and I can see the title on the packing slip in the correct position, however, the field appears blank. Here’s the code I’ve used…

    add_action( 'wpo_wcpdf_after_order_data', 'woops_sage_customer_number', 10, 2 );
    function woops_sage_customer_number ($template_type, $order) {
        if ($template_type == 'packing-slip') {
            ?>
    	     $customerid = $order->get_user_id(); ?>
    
    	 	<tr class="customer-number">
    	        <th>Customer Number:</th>
    	        <td><?php the_field( 'customer_number', $customerid ); ?></td>
    	    </tr>
    	    <?php
    	}
    }

    Any help would be greatly appreciated.

    Many thanks,
    Matt

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

    (@pomegranate)

    From the ACF documentation it looks like the_field() requires a user_ prefix to the post id to distinguish it from post (order) meta. I think this will work:

    
    <?php the_field( 'customer_number', "user_{$customerid}" ); ?>
    

    I did also notice that I had an incorrect PHP closing tag in the first code. It still didn’t work with that code, however, it did work when using it as a variable.

    add_action( 'wpo_wcpdf_after_order_data', 'woops_sage_customer_number', 10, 2 );
    function woops_sage_customer_number ($template_type, $order) {
        if ($template_type == 'packing-slip') {
    
    	     $customerid = $order->get_user_id();
    
    	     $customerno = get_field('customer_number', 'user_'. $customerid );
    	     if ($customerno) {
    	      ?>
    
    		    <tr class="customer-number">
    		        <th>Customer Number:</th>
    		        <td><?php echo $customerno; ?></td>
    		    </tr>
    		    <?php
    		}
    	}
    }'

    Thank you for your help and swift reply!

    • This reply was modified 1 month, 3 weeks ago by  seemorematt.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.