• liquid8

    (@liquid8)


    Hi,

    I am making a plugin where I have done the following at one point of the code:

    global $woocommerce;
    $order = new WC_Order($orderID);

    I am getting this error:
    Fatal error: Class ‘WC_Order’ not found in /

    By googling I have only found the solutions where the answer has been to add that global $woocommerce to my code before using the WC_Order-class. This code is inside my custom class. What am I missing here? ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I suspect a timing issue where your code is run before Woo has declared WC_Order. I don’t know if Woo even declares WC_Order for all requests or just cart related requests. You need to determine a proper action hook ( and add using a late priority ) to run your code from to insure the class has been declared. Additionally, check if class_exists( 'WC_Order' ) before proceeding, and if it does not exist fail gracefully.

    Thread Starter liquid8

    (@liquid8)

    Thank you, I figured it out now. I decided to add action to ‘plugins_loaded’ -hook. That did the trick.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WC_Order -class not found’ is closed to new replies.