Get the last booked listing order

Hi,

I want a function that returns the last completed order of listing related to a given Vendor (host)
something like :

function get_last_completed_order( $vendor_id ){
...
}

Or is there a prebuilt function that I can use instead

Thanks

It is possible to get the last vendor order with the wc_get_orders function, where you should pass these parameters

'limit' => 1,
'meta_key'   => 'hp_vendor',
'meta_value' => put vendor id here,
'orderby'       => 'date',
'order'         => 'DESC',

After getting the order, it is possible to get a listing by getting the parent id of the order’s product in this way.

\HivePress\Models\Listing::query()->get_by_id(put here order's product parent id);

If you are not familiar with the code customization, then please consider hiring someone for custom work https://fvrr.co/32e7LvY

1 Like

Thank you @yevhen it’s working :wink: