Problem: I have a View of WooCommerce Orders that shows the products in each order. I would also like to show the quantity of each product.
Solution: At this time, there isn't a built-in way to do this, it's only possible to display each Product from the Order. I have a custom shortcode here that can help. Add this to your child theme's functions.php file:
function order_product_qty_func($atts) { $a = shortcode_atts( array( 'orderid' => '', 'productid' => '' ), $atts ); // get the order using the orderid shortcode attribute $order = wc_get_order( $a['orderid'] ); // loop over the order items foreach ($order->get_items() as $item_id => $item_data) { // Get an instance of corresponding the WC_Product object $product = $item_data->get_product(); $product_id = $product->get_id(); // Get the product id // if the product id matches the current product id in the loop, return the qty if( $product_id == $a['productid'] ) return $item_data->get_quantity(); } return; } add_shortcode( 'order_product_qty', 'order_product_qty_func');
In the View of Ordered Products, add the Order ID to the View shortcode as an attribute like this:
[wpv-view name="List of Ordered Products" ids="[wpv-ordered-product-ids]" orderid="[wpv-post-id]"]
Then in the Loop Output of the Ordered Products View, you can access the orderid and include the new custom shortcode like this:
[order_product_qty productid="[wpv-post-id]" orderid="[wpv-attribute name='orderid']"][/order_product_qty]
Relevant Documentation:
https://toolset.com/learn/create-an-ecommerce-wordpress-site/displaying-more-information-from-woocommerce/how-to-display-woocommerce-orders-on-the-front-end/
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 6 replies, has 3 voices.
Last updated by 6 years, 9 months ago.
Assisted by: Christian Cox.