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.
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.
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:
- 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:
- 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.
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.
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.
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.
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.
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.
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.
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