Skip Navigation

[Resolved] Display Woocommerce orders on front-end

This support ticket is created 3 years, 10 months 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 19 replies, has 2 voices.

Last updated by dmitryK-2 3 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1629931

Tell us what you are trying to do?

Hi , I need a help of making the following - I have a webinars (wc products) on my site & I want managers to check attendees (wc customers) orders and payments via report via front-end View (1 product many orders).

So, I need to adjust logic shown here - https://toolset.com/learn/create-an-ecommerce-wordpress-site/displaying-more-information-from-woocommerce/how-to-display-woocommerce-orders-on-the-front-end/, showing Products breaking down by Orders (means vice versa described in this manual).

I've created an View "sht-adm_orders-prod_list" - shows all products, and subsidary View "sht-adm_orders-list" which needs to be filtered by 'prodid' shortcode attribute

I also found a good snippet of code https://toolset.com/forums/topic/show-orders-by-product-author/ , but my php is low, so a can't convert it into custom shortcode something like "[get_orders_by_product_id]".

So is it possible to create shortcode which will do with logiс described?

*** *** ***

BR, Dima

#1630073

I've also find this one for selecting all Orders for a given Product: https://stackoverflow.com/questions/45848249/woocommerce-get-all-orders-for-a-product

#1630093

so the first draft of code. looks like this but it doesn't works (showing "No results found" in View):

/**
 * Get All orders IDs for a given product ID.
 *
 * @param  integer  $product_id (required)
 * @param  array    $order_status (optional) Default is 'wc-completed'
 *
 * @return array
 */

function get_orders_ids_by_product_id_fn( $atts , $order_status = array( 'wc-completed' ) )

{
    global $wpdb;

        // Attributes
            $atts = shortcode_atts(
                array(
                    'prodid' => '',
                ),
                $atts
            );

    $results = $wpdb->get_col("
        SELECT order_items.order_id
        FROM {$wpdb->prefix}woocommerce_order_items as order_items
        LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
        LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
        WHERE posts.post_type = 'shop_order'
        AND posts.post_status IN ( '" . implode( "','", $order_status ) . "' )
        AND order_items.order_item_type = 'line_item'
        AND order_item_meta.meta_key = '_product_id'
        AND order_item_meta.meta_value = '$prodid'
    ");

    return $results;
}

add_shortcode( 'get_orders_by_product_id', 'get_orders_ids_by_product_id_fn' );
#1630103
Screenshot 2020-05-19 at 13.38.20.png

shortcode I use in "sht-adm_orders-prod_list" View:

[wpv-view name='sht-adm_orders-list' prodid='[get_orders_by_product_id]']
#1630217

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As the the following Doc describes , have you registered your custom shortcode:
=> https://toolset.com/documentation/adding-custom-code/how-to-create-a-custom-shortcode/#using-the-custom-shortcode
At

Toolset -> Settings page, click the Front-end Content tab and add your shortcode name in the Third-party shortcode arguments section.

If yes, have you also added the query filter to your view that catch the prodid view's shortcode attribute value?

#1630329
Screenshot 2020-05-19 at 15.54.17.png
Screenshot 2020-05-19 at 15.53.04.png

HI Minesh, sure

Shortcode registred, code added in functions.php (see attached)
In query filter 'prodid' attribute is added (see attached)

#1631393

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It looks like the issue is from the custom shortcode you added.

you are returning the results as given under - but it seems the $result variable contains the array.

return $results;

Can you please change the above line of code as given under - where we are joining the array elements with comma and generating the comma-separated string.

return join(",",$results);

Can you please make above check and let me know if that works or not.

#1631845

Hm, done this adjustment
No luck. Still "No items found"

#1631883

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I need access details and problem URL so I can check whats going wrong.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1631967
Screenshot 2020-05-19 at 13.38.20.png

Please choose tab #3 after logon:

#1631979
Screenshot 2020-05-19 at 13.38.20.png

Please choose tab #3 after logon

#1632239

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I would like to know where you added the shortcode "get_orders_by_product_id"? To your theme? If yes: I do not have capabilities to edit your theme.

Can you please send me FTP access details and tell me where exactly you added the code?

I have set the next reply to private which means only you and I have access to it.

#1632723

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked the code you wrote now and I see it needs to pass order_status and prodids to the shortcode you added.

I think you are using the shortcode wrongly as you do not pass the shortcode attribute order_status and prodids to the shortcode.

I would like to know first, what orders you would like to display?
- do you want to display all orders? or
- do you want to display orders belongs to current logged in user?

#1633127

Great we have a solution!

I need to display all orders with: wc-pending wc-on-hold wc-cancelled wc-failed wc-processing wc-completed wc-refunded statuses

#1633141

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

So, your concern here is to display all orders with those status (wc-pending wc-on-hold wc-cancelled wc-failed wc-processing wc-completed wc-refunded) irrespective of any user - correct?

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