Run the code after the framework is loaded

Hello everyone,

I’m developing a custom function to create a WooCommerce order immediately after a user accepts an offer. I’ve encountered a very persistent technical issue where the HivePress API is not fully initialized when my code runs.

My Environment Setup:

  1. My custom PHP code is running from an MU-Plugin file.

  2. I am hooking into the init action at the highest priority (999) to ensure late execution.

  3. The main hivepress() function exists.

The Problem:

When my code attempts to access the models object (e.g., hivepress()->models->get('offer')), the $models property is NULL.

The Diagnostic Proof:

We have confirmed this is a dependency issue, as my debug log shows the function is running, but the dependency is not ready:

[HP_AcceptOffer] core called; offer_id=XX; user=YY
[HP_AcceptOffer] HivePress function exists. Proceeding to API calls.
[HP_AcceptOffer] Models NULL after core check. Fatal plugin conflict suspected.
[HP_AcceptOffer] Redirection handler failed: API Error: HivePress models failed to initialize during standard page load. Check plugin order.

(Note: I have removed server path information from the full log.)

Question for the Community/Developers:

What is the official HivePress hook or the recommended method to ensure the $models object is fully initialized and guaranteed to be available before accessing the API in a non-AJAX context (like a standard form submission handler on the init hook)?

Thank you for any architectural guidance!

Hi,

Thank you for the details. Could you please let us know where you found hivepress()->models? There is no such method for retrieving a model, and no component called models.

Please provide more details about which parameters you want to use to get the offer and in which event [hook] you want to perform this, and we’ll provide guidance.

Hi kseniia,

Thanks so much for the swift reply and for giving me a heads-up about the API structure! You totally saved me from chasing a ghost—I definitely had some old or just plain wrong info about using hivepress()->models floating around. My bad!

You’re right, I need to know the current, official way to talk to the HivePress models.

So, what am I trying to do?

I’m basically building a simple flow: when a user hits “Confirm & Pay” after seeing an offer, I need to secretly turn that offer into an official, payable order in the background.

Goal: Retrieve a specific offer object by its Offer ID ($offer_id).

Next Step: Use that retrieved offer object to then create a brand new order object.

Timing: This has to run right after a form submission. For stability, I’m currently running the code in a full page handler hooked to init with a super-late priority of 999.

And for me, it seems the real issue is the timing conflict.

Even if my API call was working, the main issue is that the core HivePress components needed for object retrieval are NULL when my code runs on that init hook. It seems like a tough timing conflict.

Hence, I’m hoping you can help me with thesetwo things:

A. What’s the official, current function to correctly pull an offer object by its ID? (e.g., is there a wrapper like hp_get_offer( $id )?

B. What is the absolute safest, most guaranteed WordPress hook (and maybe a recommended priority) that ensures all the necessary HivePress model components are loaded and ready to be used?

I believe that with these two pieces of guidance I´ll put the final puzzle pieces in their places. Again, thanks for your help with this one

Cheers,
Rodrigo

Thanks for the details. If you have the offer ID, you can do this:

$offer = \HivePress\Models\Offer::query()->get_by_id($offer_id);

Then you can access any offer fields like $offer->get_price() for example.

Please let me know if you mean the WooCommerce order, because if so then the Accept Offer button (if you also have the Marketplace extension enabled) does the same – it redirects user to WooCommerce checkout to pay, which creates a new order. It may be easier to customize the existing flow if needed.

Hope this helps

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