• Resolved andreajbradley

    (@andreajbradley)


    Hi there,

    Love this plugin – thank you πŸ™‚

    I am having trouble with the Webhooks however on one particular website, they’re all failing with a server 500 error.

    These are the logs:

    2021-11-29T00:00:06+00:00 CRITICAL Uncaught Error: Call to a member function get_cart_contents_count() on null in /home/******/******/***.***.co.uk/www/wp-content/themes/***/***/woocommerce-cart-custom-data.php:153
    Stack trace:
    #0 /home/******/******/***.***.co.uk/www/wp-includes/class-wp-hook.php(303): {closure}('')
    #1 /home/******/******/***.***.co.uk/www/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
    #2 /home/******/******/***.***.co.uk/www/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
    #3 /home/******/******/***.***.co.uk/www/wp-settings.php(600): do_action('wp_loaded')
    #4 /home/******/******/***.***.co.uk/www/wp-config.php(124): require_once('/home/***/vh...')
    #5 /home/******/******/***.***.co.uk/www/wp-load.php(50): require_once('/home/***/vh...')
    #6 /home/******/******/***.***.co.uk/www/wp-cron.php(44): require_once('/home/***/vh...')
    #7 {main}
      t in /home/******/******/***.***.co.uk/www/wp-content/themes/***/***/woocommerce-cart-custom-data.php on line 153

    This isn’t a theme that I developed, but the part of the file it’s referring to is:

    add_filter('wp_loaded', function () {
        if (!is_admin()) {
    ***     if (WC()->cart->get_cart_contents_count() == 0) {
                WC()->session->__unset('cart_created_time');
            } else {
    
                // items in cart.
                $cartCreatedTime = WC()->session->get('cart_created_time');
    
                if (!$cartCreatedTime) {
                    WC()->session->set('cart_created_time', time());
                }
            }
    
            check_session();
        }
    });

    I highlighted line 153 with ***.

    Is this something you could help me with please?

    Thanks so much.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Clayton R

    (@mrclayton)

    Hi @andreajbradley,

    The error, as you have pointed out, is being caused by your theme, not the Stripe plugin.

    The reason this error is being encountered is your theme is calling WC()->cart which is only instantiated for frontend requests, not REST requests.

    Your theme should have an additional check to make sure either the cart exists or this isn’t a REST request.

    Something like this:

    if(!is_admin() && WC()->cart){
    
    }

    Kind Regards,

    Thread Starter andreajbradley

    (@andreajbradley)

    Wow, thank you so much for your prompt reply!

    I updated the code as suggested and the endpoints now work.

    Amazing support, thank you πŸ™‚

    Plugin Author Clayton R

    (@mrclayton)

    Hi @andreajbradley,

    Thank you for the great review.

    Kind Regards,

    Thread Starter andreajbradley

    (@andreajbradley)

    Different topic – and not sure if the theme is to blame again – but the refund button on the order page prints the buttons text with <span class=”currency”>Β£</span>.

    It’s not causing any issues but just an FYI

    Thanks again for your help today.

    Plugin Author Clayton R

    (@mrclayton)

    Hi @andreajbradley,

    The Stripe plugin does not render the refund button so it would be some other functionality that’s causing the html to be rendered as text.

    Kind Regards,

    Thread Starter andreajbradley

    (@andreajbradley)

    I thought that might be the case, thank you for coming back to me πŸ™‚

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Internal server 500 error on Webhooks’ is closed to new replies.