Skip Navigation

[Resolved] Show orders by product author

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to filter the list of orders by the current product author. This means that if an author views his profile then he can view all the orders that were made on his product.

Solution:
I've made a custom shortcode that should be able to get the product id of the current order and pass it to your list orders view.

Add the following to your functions.php file

// Add Shortcode
function get_ordered_products_id( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'order_id' => '',
        ),
        $atts
    );
 
    $order = wc_get_order( $atts['order_id'] ); 
    $product_ids = array( );;
     
    // Iterating through each "line" items in the order
    foreach ($order->get_items() as $item_id => $item_data) {
     
        // Get an instance of corresponding the WC_Product object
        $product = $item_data->get_product();
        array_push($product_ids, $product->get_ID()); // Get the product name
    }
 
    //$new_product_ids = str_replace(" ",",",$product_ids);
 
    return implode(',',$product_ids);
 
}
add_shortcode( 'get_ordered_products_id', 'get_ordered_products_id' );

This shortcode is used by calling it like this [get_ordered_products_id order_id='192'] where 192 will be the order id. You can also use it with the views [wpv-post-id] shortcode by passing it into the shortcode like this [get_ordered_products_id order_id='[wpv-post-id]']

So to use this in the view you need to add "get_ordered_products_id" shortcode name to the views 3rd party shortcode arguements that can be found in Toolset->Settings->Frontend Content.

So this should be added to your Orders view inside the tags. The only thing that should be within those tags is this.

[wpv-view name="list-of-ordered-products" ids="[get_ordered_products_id order_id='[wpv-post-id]']"]
This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 16 replies, has 3 voices.

Last updated by Shane 6 years ago.

Assisted by: Shane.

Author
Posts
#686999

Hi!

I'm building a multi-vendor website. I let users upload products to sell and I want to display all the orders related to a seller (post/product author) so he can ship the products to the buyer.

Is this possible to achieve with Toolset?

I have been following this tutorial (https://toolset.com/learn/create-an-ecommerce-wordpress-site/displaying-more-information-from-woocommerce/how-to-display-woocommerce-orders-on-the-front-end/) but so far I couldn't figure out how to only show the orders related to that seller products.

Thanks

#687878

Hi, I don't think there is an easy way to filter a View of Orders by Product Author without using custom code and the wpv_filter_query API. A somewhat complex approach that does not require code follows here:
- In the Loop Output of the List of Orders View you created in the tutorial, remove everything from inside the wpv-loop tags.
- Insert the shortcode for the View of Products just above the first wpv-loop tag. Add the attribute "orderid" to this View shortcode and pass in the current Order ID, like this:

[wpv-view name="your-products-view-slug" orderid="[wpv-post-id]"]

- In the View of Products, add a Post Author filter and filter by the current User.
- In the Loop Output of the View of Products, remove everything inside the wpv-loop tags. Just above the first wpv-loop tag, insert the post link shortcode referencing the orderid attribute you just added:

[wpv-post-link id="[wpv-attribute name='orderid']"]

- Now you have a View of Orders that will loop over all the Orders in your system. Inside that Loop, you have a View of Products filtered by Post Author. If any results are Products by the current User are found, this View will display the link to the Order.

The main disadvantage to this approach is that pagination is not possible, because some Orders will not be displayed in the list even though they are results in the View of Orders. We have suppressed the display of some of those Orders (the ones that do not include Products by the current User), and the pagination system is not smart enough to compensate for that type of conditional approach. Let me know if you have questions about this.

#689374

Hi Christian! Thanks for your answer!

Unfortunately, it only gives me a link to view the current page where I'm displaying the view. Something is not working because even if I remove:
[php]id="[wpv-attribute name='orderid']"</code
it still shows the same thing.

I attached 2 screenshots of the List of Orders and the Product View.

Thank you!

#689376
list-orders.png
products-view.png

Hi Christian! Thanks for your answer!

Unfortunately, it only gives me a link to view the current page where I'm displaying the view. Something is not working because even if I remove id="[wpv-attribute name='orderid']" it still shows the same thing.

I attached 2 screenshots of the List of Orders and the Product View.

Thank you!

#692217

I see, I think I gave you inaccurate directions. Please edit the View of Orders and move the View of Products inside the wpv-loop tags and let me know the results.

#692998

I did that and what I get is a list of all orders and not only the orders for the user's products.

#693000

So I think that the main query it's not working. Because even if I remove the orderid='[wpv-post-id]' I get exactly the same thing.

#694256

Okay may I log in and take a closer look in your wp-admin area? I will activate private reply fields here. Please let me know where I can find the Views we've been discussing, on the front-end of your site.

#694557
Screen Shot 2018-04-19 at 3.53.18 PM.png
Screen Shot 2018-04-19 at 3.51.03 PM.png

Sorry but I'm not able to get to a login, wp-admin just loads and loads and loads. Too many redirects. I see in the console that wp-admin returns a 302, then loads again, then another 302, then loads again, and so on. Is there an IP restriction or other security plugin in place? Some SSL configuration issue? I tried wp-login.php too, but the login page shows up with no styles.

#694711

Have you tried with the https ?

Can't figure out what could be. I already had someone from China logging in so don't believe it's an IP restriction.

#694714

I'm not able to get in, but another supporter here is not having the same issue. Maybe it's a DNS problem on my end. I will reassign the ticket to Shane, and he will follow up with you soon.

#697820

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nuno,

I'm currently having a look at this for you .

Thanks,
Shane

#697844

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nuno,

I'm experiencing the same issue that Christian is experiencing.

In this case would you mind providing a duplicator package so that I can see if I can setup the site locally and do the tests there ?

To provide the duplicator please have a look at the link below.
https://toolset.com/faq/provide-supporters-copy-site/

Thanks,
Shane

#700254

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nuno,

Thank you.

I took a short search through our forums and was able to find a solution to this for you.
https://toolset.com/forums/topic/sites-users-personal-product-list/

Please try the solution and let me know if this helps.

Thanks,
Shane

#700321

Hi Shane,
The problem isn't the same.

In my site everyone can sell and buy products. What I want is to show all the orders related to the products a user upload so he can ship the product to the buyer.

Use case:
UserSeller -> Uploads a product
UserBuyer -> Bought a product from UserSeller
UserSeller -> Sees a page where he can see who bought his products and see the order

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.