Support » Plugin: WooCommerce Admin » PHP Fatal error Call to a member function get_type() on boolean

  • Resolved alx359

    (@alx359)


    Had this on my debug.log today [WP_DEBUG=true]:

    PHP Fatal error: Uncaught Error: Call to a member function get_type() on boolean in \plugins\woocommerce-admin\includes\data-stores\class-wc-admin-reports-coupons-data-store.php:362

    Reading the offending like it becomes apparent the false == wc_get_order() case isn’t being handled:

    $order = wc_get_order( $order_id );
    
    // Refunds don't affect coupon stats so return successfully if one is called here.
    if ( 'shop_order_refund' === $order->get_type() ) {
    	return true;
    }

    In other parts on your code you do such check like this:

    if ( ! $order ) {
    	return -1;
    }

    So this block of code shall become like this:

    $order = wc_get_order( $order_id );
    
    if ( ! $order ) {
    	return -1;
    }
    
    // Refunds don't affect coupon stats so return successfully if one is called here.
    if ( 'shop_order_refund' === $order->get_type() ) {
    	return true;
    }

    Searching your code for other instances of wc_get_order we can see the same potential issue here:

    \plugins\woocommerce-admin\includes\data-stores\class-wc-admin-reports-taxes-data-store.php line 314:

    public static function sync_order_taxes( $order_id ) {
    	global $wpdb;
    	$order       = wc_get_order( $order_id );
    	$tax_items   = $order->get_items( 'tax' );

    and here:

    \plugins\woocommerce-admin\includes\api\class-wc-admin-rest-reports-controller.php line 189:

    $order = new WC_Order( $order_id );
    
    if ( 'shop_order' !== $order->get_type() ) {
    	return $order_id;
    }

    HTH.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.