I am suffering from a bug. Can’t get order information. At first, I thought that the problem was in some plugins, turned everything off. And then completely created a new WP with only Woocommerce and a standard theme. Still the same error. Please, help me.
Fatal error: Uncaught Error: Call to a member function get_data() on
boolean in
W:domainscafe2wp-contentthemesenvo-shopperfunctions.php:501
Stack trace: #0 W:domainscafe2wp-settings.php(555): include() #1
W:domainscafe2wp-config.php(96):
require_once(‘W:domainscafe…’) #2
W:domainscafe2wp-load.php(50): require_once(‘W:domainscafe…’)
#3 W:domainscafe2wp-blog-header.php(13): require_once(‘W:domainscafe…’) #4
W:domainscafe2index.php(17): require(‘W:domainscafe…’) #5
{main} thrown in
W:domainscafe2wp-contentthemesenvo-shopperfunctions.php on line
501 There has been a critical error on this website.
$order_id = 12;
$order = wc_get_order( $order_id );
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
2
Answers
So, the problem was that in wp you can't request orders before the custom post type is registered.
I used woocommerce_after_register_post_type hook like this:
Hope this helps someone in the future.
You should check if
returns a correct value.
I’d do it this way (untested):
Infos: https://wp-kama.com/plugin/woocommerce/function/wc_get_order