• Resolved Dennis Jansen

    (@dennisjjansen)


    My customer uses the free Kadence WooCommerce Email Designer, but when editing emails, sees the message: “A critical error has occurred on this site”. See attached screenshot.

    When testing, I see that this is because of a conflict with the Pre-Orders For WooCommerce plugin: if I disable that plugin, the error message disappears and I can visually see the editor and the results of the changes I’m making in the left side fields of the Kadence Email Designer plugin.

    This is the error message from the log and underneath that a cause for the error, based on a reply from a WooCommerce forum member:

    Uncaught Error: Call to a member function get_meta() on bool in /home/website199/domains/ourwebsite.com/public_html/wp-content/plugins/pre-orders-for-woocommerce/src/Checkout.php:67 CONTEXT: {“error”:{“type”:1,”file”:”\/home\/website199\/domains\/ourwebsite.com\/public_html\/wp-content\/plugins\/pre-orders-for-woocommerce\/src\/Checkout.php”,”line”:67},”backtrace” “”,”#0 \/home\/website199\/domains\/ourwebsite.com\/public_html\/wp-includes\/class-wp-hook.php(324): Woocommerce_Preorders\Checkout->setPreroderStatus()”,”#1 \/home\/website199\/domains\/ourwebsite.com\/public_html\/wp-includes\/plugin.php(205): WP_Hook->apply_filters()”,”#2 \/home\/website199\/domains\/ourwebsite.com\/public_html\/wp-content\/plugins\/woocommerce\/includes\/class-wc-order.php(323): apply_filters()”,”#3 \/home\/website199\/domains\/ourwebsite.com\/public_html\/wp-content\/plugins\/woocommerce\/includes\/class-wc-order.php(300): WC_Order->maybe_set_date_paid()”,”#4 \/home\/website199\/domains\/ourwebsite.com\/public_html\/wp-content\/plugins\/woocommerce\/includes\/abstracts\/abstract-wc-data.php(801): WC_Order->set_status()”,”#5 \/home\/website199\/domains\/ourwebsite.com\/public_html\/wp-content\/plugins\/kadence-woocommerce-email-designer\/includes\/class-kadence-woomail-p”]}

    Cause:

    The error message you see, Uncaught Error: Call to a member function get_meta() on bool, indicates that a method (get_meta) is being called on a boolean value instead of an object. This is done in the Checkout.php file of the pre-orders-for-woocommerce plugin.

    Based on this error, how can I solve this error, so that both Pre-Order and Kadence Email Customizer plugins work?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Dennis Jansen

    (@dennisjjansen)

    This solved the issue for me (with a little ChatGPT help):
    
    The line causing the problem is:
    
    if ( $order->get_meta( '_pre_order_date' ) ) {
    
    To resolve the error message "Uncaught Error: Call to a member function get_meta() on bool", ensure that $order is a valid object before calling the get_meta() method.
    
    In the checkWholeOrders() function, $order is obtained via wc_get_order(), but it seems there may be a problem getting the order information.
    
    To address this issue, you can make the following changes:
    
    public function checkWholeOrders( $order_id ) {
    
    $order = wc_get_order( $order_id );
    
    if ( $order ) { // Check if $order is a valid object
    
    if ( $order->get_meta( '_preorder_date' ) ) {
    
    $order->set_status( 'wc-pre-ordered' );
    
    $order->save();
    
    }
    
    }
    
    }
    
    By adding the if ($order) condition, you check that $order is a valid object before calling the get_meta() method. This prevents the error message if $order is not initialized correctly. This change actually solved the problem.
    
    And you can use a hook in the theme's functions.php file or in a custom plugin to make the changes you want without having to rely on updates to the Pre-Orders for WooCommerce plugin. You can use the woocommerce_checkout_update_order_meta hook for this, which runs when the order metadata is updated during the checkout process. Here's how you can do it:
    
    // Voeg de functie toe die de orderstatus controleert en bijwerkt
    function custom_check_whole_orders( $order_id, $data ) {
        $order = wc_get_order( $order_id );
        if ( $order ) { // Controleer of $order een geldig object is
            if ( isset( $data['preorder_date'] ) ) {
                $order->update_meta_data( '_preorder_date', esc_attr( $data['preorder_date'] ) );
            } else {
                global $woocommerce;
                $cart = $woocommerce->cart->get_cart();
                $checkout = new Woocommerce_Preorders\Checkout(); // Instantieer de Checkout-klasse om toegang te krijgen tot de benodigde methoden
                $checkout->checkPreOrderProducts( $cart ); // Roep de checkPreOrderProducts-methode aan om pre-orderproducten te controleren
                if ( count( $checkout->getPreOrderProducts() ) > 0 ) {
                    $oldestDate = str_replace( [' 00:00:00'], [''], $checkout->getOldestDate() );
                    $order->update_meta_data( '_preorder_date', esc_attr( $oldestDate ) );
                }
            }
            $order->save();
        }
    }
    
    // Voeg de hook toe om de functie aan te roepen
    add_action( 'woocommerce_checkout_update_order_meta', 'custom_check_whole_orders', 10, 2 );
    
    This code will run the custom_check_whole_orders function every time the order metadata is updated during the checkout process. It will provide the same functionality as the original checkWholeOrders function, but now it is called via a hook outside the plugin, so it is not dependent on plugin updates.
    Plugin Author Kleinmann

    (@kleinmannbrightvessel)

    Hello,
    I hope you are well

    Thanks for sharing your feedback,
    Checking the log you have provided, I can see that the error arose here:

    Uncaught Error: Call to a member function get_meta() on bool in /home/website199/domains/ourwebsite.com/public_html/wp-content/plugins/pre-orders-for-woocommerce/src/Checkout.php:67

    public function setPreroderStatus( $status, $order_id, $order ) {
    	$order = wc_get_order( $order_id );
    
    	if ( $order->get_meta( '_preorder_date' ) ) {
    		return 'pre-ordered';
    	}
    	
    	return $status;
    }

    So the error occurred because?wc_get_order()?returned a boolean value., most likely did not find the $order_id

    Therefore, it is good to add a similar conditional statement as you mentioned, to avoid these errors, something like this:

    .....
    
    //Conditional statement
    if ( ! $order ) {
    	return $status;
    }
    
    .....

    We will improve it for the next version, thx !

    – Best Regards

    Thread Starter Dennis Jansen

    (@dennisjjansen)

    That is great, thanks for getting back, looking forward to the update. All the best for now and thanks again.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Critical error – method on boolean value instead of object’ is closed to new replies.