Home Forums Front-end Issues Display field value for shop_order


Display field value for shop_order

  • Hi there!

    I’m trying to display a simple text field value for post type ‘shop_order’ however nothing will appear.

    I’m using the below code to display the orders for the current logged in user, which works, but the field isn’t coming up. I couldn’t find any documentation on this, any help is greatly appreciated!

    		$customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array(
    			'numberposts' => $order_count,
    			'meta_key' => '_customer_user',
    			'meta_value' => get_current_user_id(),
    			'post_type' => 'shop_order',
    			'post_status' => 'publish'
    		) ) );
    		foreach ( $customer_orders as $customer_order ) :
    			$order = new WC_Order();
    			$order->populate( $customer_order );
    			$status = get_term_by( 'slug', $order->status, 'shop_order_status' );
    			$item_count = $order->get_item_count();
    			<p><?php the_field( 'mm_challenge_test', $order_id ); ?></p>
    		<?php endforeach; ?>
  • I found the issue immediately:

    the_field( 'mm_challenge_test', $order_id );

    actually needs to be:

    the_field( 'mm_challenge_test', $order->id );

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Display field value for shop_order’ is closed to new replies.