How to inject custom attributes to WooCommerce orders?

Hey guys,

at first, great product! It is really well-built and the code is spotless.
We are using HivePress alongside Listings, Marketplace, Reviews & Requests extensions. Now we want to create a cronjob which sends data for every order, where execution day = today.

How could we assign an execution_day custom field the best way, so we can query it later on via our script? Do custom attributes from a Request get automatically injected in a WooCom-Order or do we need to create two attributes which we map?

Your experienece regarding this would be a big help!

Thanks a lot

An update on this would be appreciated. Thanks!

At least some kind of response is appreciated, you guys are advertising with 24-hour response timeframes. Are the attributes somewhere stored in the order, or is there a relatively easy way to retrieve orders based on requests attributes?

I’m sorry for the late reply and any inconvenience caused, there were temporary delays with developer-specific issues but this is resolved now.

Yes, you can retrieve the related request via the purchased product ID (the request ID is set in “post_parent” of the purchased product), but attributes are not available automatically, you have to get the request object by ID this way:

$request=\HivePress\Models\Request::query()->get_by_id($request_id_here);

Then you can get any attribute this way:

$value=$request->get_attribute_name_here();

Hope this helps.

Appreciate your response, thanks!

Thanks a lot, the answer was really great and helped me a lot. However, just a follow-up, if possible, how can we get both the sellers and buyers with their respective informations, based on the WooCommerce order?

If you use some callback functions with the order object available, you can get customer ID using the core WooCommerce function (user ID), and vendor ID by fetching the order meta (“hp_vendor” meta field). Vendor is a custom post type “hp_vendor” so you can fetch the post author, getting the vendor user this way.

Hope this helps.

Hey Ihor,

thanks that helped us a lot. How can we retrieve information for the request connected to an order?

If you mean paid requests added via the Requests extension, the easiest way is to retrieve the purchased product ID from the order and then getting the parent ID of this product get_post_parent() – Function | Developer.WordPress.org This is the request ID, which allows you to get the request object via HivePress\Models\Request::query()->get_by_id($id) and then fetch any request details:

$request->get_title()

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.