• Resolved bee15

    (@bee15)


    Hello, I was looking at the status log, and found a Critical Uncaught Error, as shown below.

    2022-10-04T03:45:35+00:00 CRITICAL Uncaught Error: Call to a member function get_sku() on bool in /srv/htdocs/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()’d code:4
    Stack trace:
    #0 /wordpress/core/6.0.2/wp-includes/class-wp-hook.php(307): sku_before_order_item_name(‘2020 Trophy Rib…’, Object(WC_Order_Item_Product), false)
    #1 /wordpress/core/6.0.2/wp-includes/plugin.php(191): WP_Hook->apply_filters(‘2020 Trophy Rib…’, Array)
    #2 /srv/htdocs/wp-content/plugins/woocommerce/templates/order/order-details-item.php(33): apply_filters(‘woocommerce_ord…’, ‘2020 Trophy Rib…’, Object(WC_Order_Item_Product), false)
    #3 /srv/htdocs/wp-content/plugins/woocommerce/includes/wc-core-functions.php(345): include(‘/srv/htdocs/wp-…’)
    #4 /srv/htdocs/wp-content/plugins/woocommerce/templates/order/order-details.php(71): wc_get_template(‘order/order-det…’, Array)
    #5 /srv/htdocs/wp-content/plugins/woocommerce/includes/wc-core-functions.php(345): include(‘/srv/htdocs/wp-…’)
    #6 /srv/htdocs/wp-content/plugins/woocommerce/includes/wc-template-functions.php(2665): wc_get_template(‘order/order-det…’, Array)
    #7 /wordpress/core/6.0.2/wp-includes/class-wp-hook.php(307): woocommerce_order_details_table(24911)
    #8 /wordpress/core/6.0.2/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(”, Array)
    #9 /wordpress/core/6.0.2/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
    #10 /srv/htdocs/wp-content/plugins/woocommerce/templates/myaccount/view-order.php(56): do_action(‘woocommerce_vie…’, 24911)
    #11 /srv/htdocs/wp-content/plugins/woocommerce/includes/wc-core-functions.php(345): include(‘/srv/htdocs/wp-…’)
    #12 /srv/htdocs/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-my-account.php(151): wc_get_template(‘myaccount/view-…’, Array)
    #13 /srv/htdocs/wp-content/plugins/woocommerce/includes/wc-template-functions.php(3207): WC_Shortcode_My_Account::view_order(24911)
    #14 /wordpress/core/6.0.2/wp-includes/class-wp-hook.php(307): woocommerce_account_view_order(‘24911’)
    #15 /wordpress/core/6.0.2/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(”, Array)
    #16 /wordpress/core/6.0.2/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
    #17 /srv/htdocs/wp-content/plugins/woocommerce/includes/wc-template-functions.php(3142): do_action(‘woocommerce_acc…’, ‘24911’)
    #18 /wordpress/core/6.0.2/wp-includes/class-wp-hook.php(307): woocommerce_account_content(”)
    #19 /wordpress/core/6.0.2/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)
    #20 /wordpress/core/6.0.2/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
    #21 /srv/htdocs/wp-content/plugins/woocommerce/templates/myaccount/my-account.php(34): do_action(‘woocommerce_acc…’)
    #22 /srv/htdocs/wp-content/plugins/woocommerce/includes/wc-core-functions.php(345): include(‘/srv/htdocs/wp-…’)
    #23 /srv/htdocs/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-my-account.php(123): wc_get_template(‘myaccount/my-ac…’, Array)
    #24 /srv/htdocs/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-my-account.php(72): WC_Shortcode_My_Account::my_account(”)
    #25 /srv/htdocs/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php(72): WC_Shortcode_My_Account::output(”)
    #26 /srv/htdocs/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php(115): WC_Shortcodes::shortcode_wrapper(Array, ”)
    #27 /wordpress/core/6.0.2/wp-includes/shortcodes.php(356): WC_Shortcodes::my_account(”, ”, ‘woocommerce_my_…’)
    #28 [internal function]: do_shortcode_tag(Array)
    #29 /wordpress/core/6.0.2/wp-includes/shortcodes.php(228): preg_replace_callback(‘/\\[(\\[?)(woocom…’, ‘do_shortcode_ta…’, ‘<p> </p>\n[…’)
    #30 /srv/htdocs/wp-content/themes/flatsome/inc/helpers/helpers-shortcode.php(203): do_shortcode(‘<p> </p>\n[…’)
    #31 /wordpress/core/6.0.2/wp-includes/class-wp-hook.php(307): flatsome_contentfix(‘<p> </p>\n[…’)
    #32 /wordpress/core/6.0.2/wp-includes/plugin.php(191): WP_Hook->apply_filters(‘<p> </p>\n[…’, Array)
    #33 /wordpress/core/6.0.2/wp-includes/post-template.php(253): apply_filters(‘the_content’, ‘ \r\n\r\n[wooc…’)
    #34 /srv/htdocs/wp-content/themes/flatsome/page-my-account.php(30): the_content()
    #35 /wordpress/core/6.0.2/wp-includes/template-loader.php(106): include(‘/srv/htdocs/wp-…’)
    #36 /wordpress/core/6.0.2/wp-blog-header.php(19): require_once(‘/wordpress/core…’)
    #37 /wordpress/core/6.0.2/index.php(17): require(‘/wordpress/core…’)
    #38 {main}
    thrown in /srv/htdocs/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()’d code on line 4`

    If you could please let me know what I might be able to do to fix this error?
    Thanks,

    Emma

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @bee15,

    This error is coming from one of your snippets. You’re trying to access a function called get_sku on a variable holding a boolean (likely false).

    You should be able to narrow down to which snippet it is by doing a search for get_sku @line:4

    Thread Starter bee15

    (@bee15)

    Hi Shea,
    Thanks for that.
    This is the snippet with that error:

    add_filter( 'woocommerce_order_item_name', 'sku_before_order_item_name', 30, 3 );
    function sku_before_order_item_name( $item_name, $item, $is_visible ) {
        $product = $item->get_product();
        $sku = $product->get_sku();
    
        // When sku doesn't exist we exit
        if( empty( $sku ) ) return $item_name;
    
        $sku_text = __( 'SKU', 'woocommerce' ) . ': ' . $sku;
    
        // Add product permalink when argument $is_visible is true
        $product_permalink =  $is_visible ? $product->get_permalink( $item ) : '';
    
        if( $product_permalink )
            return sprintf( '<a href="%s">%s - %s</a>', $product_permalink, $sku_text, $item->get_name() );
        else
            return $sku_text . ' - ' . $item->get_name();
    }

    Unfortunately I don’t know much about PHP or coding, only very basics.
    so if there is anything there that doesn’t make sense, I don’t think I’ll be able to figure it out.

    I also have another error that ended up showing a critical error on my live site https://www.tilt.co.nz, when trying to print an invoice through with the plugin WooCommerce PDF Invoices, Packing Slips, Delivery Notes and Shipping Labels (wt-woocommerce-packing-list). I’m unsure if it’s a snippet issue or a WooCom PDF issue, as it’s not a constant, and only happened once with another team member.

    2023-03-20T00:32:15+00:00 CRITICAL Uncaught TypeError: array_multisort(): Argument #1 ($array) must be an array or a sort flag in /srv/htdocs/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()'d code:92
    Stack trace:
    #0 /srv/htdocs/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()'d code(92): array_multisort(NULL, 4, Array)
    #1 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(308): wf_pklist_order_by_id(Array, 'invoice', Object(wf_order))
    #2 /wordpress/core/6.1.1/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)
    #3 /srv/htdocs/wp-content/plugins/wt-woocommerce-packing-list/admin/modules/customizer/classes/class-customizer-product-table.php(1442): apply_filters('wf_pklist_alter...', Array, 'invoice', Object(wf_order))
    #4 /srv/htdocs/wp-content/plugins/wt-woocommerce-packing-list/admin/modules/customizer/classes/class-customizer-product-table.php(215): Wf_Woocommerce_Packing_List_CustomizerLib::generate_product_table_product_row_html(Array, 'invoice', Object(wf_order))
    #5 /srv/htdocs/wp-content/plugins/wt-woocommerce-packing-list/public/modules/invoice/invoice.php(438): Wf_Woocommerce_Packing_List_CustomizerLib::set_product_table(Array, 'invoice', '<div class="wft...', Object(wf_order))
    #6 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(308): Wf_Woocommerce_Packing_List_Invoice->generate_template_html(Array, '<div class="wft...', 'invoice', Object(wf_order), NULL, NULL)
    #7 /wordpress/core/6.1.1/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)
    #8 /srv/htdocs/wp-content/plugins/wt-woocommerce-packing-list/admin/modules/customizer/customizer.php(926): apply_filters('wf_module_gener...', Array, '<div class="wft...', 'invoice', Object(wf_order), NULL, NULL)
    #9 /srv/htdocs/wp-content/plugins/wt-woocommerce-packing-list/public/modules/invoice/invoice.php(998): Wf_Woocommerce_Packing_List_Customizer->generate_template_html('<div class="wft...', 'invoice', Object(wf_order))
    #10 /srv/htdocs/wp-content/plugins/wt-woocommerce-packing-list/public/modules/invoice/invoice.php(964): Wf_Woocommerce_Packing_List_Invoice->generate_order_template(Array, 'TNZ-3910753488')
    #11 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(308): Wf_Woocommerce_Packing_List_Invoice->print_it(Array, 'print_invoice')
    #12 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
    #13 /wordpress/core/6.1.1/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
    #14 /srv/htdocs/wp-content/plugins/wt-woocommerce-packing-list/admin/class-wf-woocommerce-packing-list-admin.php(818): do_action('wt_print_doc', Array, 'print_invoice')
    #15 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(308): Wf_Woocommerce_Packing_List_Admin->print_window('')
    #16 /wordpress/core/6.1.1/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
    #17 /wordpress/core/6.1.1/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
    #18 /wordpress/core/6.1.1/wp-settings.php(617): do_action('init')
    #19 /srv/htdocs/wp-config.php(97): require_once('/wordpress/core...')
    #20 /wordpress/core/6.1.1/wp-load.php(55): require_once('/srv/htdocs/wp-...')
    #21 /wordpress/core/6.1.1/wp-admin/admin.php(34): require_once('/wordpress/core...')
    #22 /wordpress/core/6.1.1/wp-admin/index.php(10): require_once('/wordpress/core...')
    #23 {main}
      thrown in /srv/htdocs/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()'d code on line 92
    

    Thanks, any help would be appreciated.

    Plugin Author Shea Bunge

    (@bungeshea)

    Adding a check to make sure that get_product actually returns a product should remove the bug:

    add_filter( 'woocommerce_order_item_name', function ( $item_name, $item, $is_visible ) {
    	$product = $item->get_product();
    	$sku = $product ? $product->get_sku() : null;
    
    	// When sku doesn't exist we exit
    	if ( empty( $sku ) ) {
    		return $item_name;
    	}
    
    	$sku_text = __( 'SKU', 'woocommerce' ) . ': ' . $sku;
    
    	// Add product permalink when argument $is_visible is true
    	$product_permalink = $is_visible ? $product->get_permalink( $item ) : '';
    
    	if ( $product_permalink ) {
    		return sprintf( '<a href="%s">%s - %s</a>', $product_permalink, $sku_text, $item->get_name() );
    	} else {
    		return $sku_text . ' - ' . $item->get_name();
    	}
    }, 30, 3 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘CRITICAL Uncaught Error’ is closed to new replies.