• Resolved conceptcorenl

    (@conceptcorenl)


    Hello,

    I am using a php plugin to write php in a page that I need.
    Is there a nice and clean way to get the item information for a user ?

    I am using a foreach since there will be more users in the long term.

    this is what I have now :

    <?php
    // Array of stdClass objects.
    foreach ( $alleKlanten as $user ) {
        echo '<span>' . esc_html( $user->display_name ) . '</span>';
    
    	$customer_orders = get_posts( array(
    	    'numberposts' => -1,
    	    'meta_key'    => '_customer_user',
    	    'meta_value'  => get_current_user_id(),
    	    'post_type'   => "shop_order",
    	    'post_status' => array_keys( wc_get_order_statuses() ),
    	) );
    	echo "<hr>";
    
    	/**
    	 * Verkrijg hier alle order informatie die is doorgezet.
    	 */
    	foreach ($customer_orders as $order) {
    
    	var_dump(
    		$wpdb->get_results( "SELECT * FROM wp_woocommerce_order_items WHERE order_id = {$order->ID} " ));
    	}
    }
    
    ?>

    It does return nothing.

    https://wordpress.org/plugins/woocommerce/

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

    (@mikejolley)

    Use the wc_get_orders() and wc_get_order() functions. Don’t use direct sql queries.

    If you need help developing your customisation, consider jobs.wordpress.net

    Thread Starter conceptcorenl

    (@conceptcorenl)

    I figured it out already thanks to you documentation website.
    I am completely new to wordpress so please don’t mind my questions please.

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

The topic ‘For user order item information’ is closed to new replies.