• Resolved Imageastahov006

    (@astahov006)


    Hello!

    I noticed the following messages in error log:

    2024/12/09 16:31:33 [error] 1237062#1237062: *2013129 FastCGI sent in stderr: “PHP message: PHP Warning: Attempt to read property “total” on null in /mysite.ru/wp-content/plugins/code-snippets/php/snippet-ops.php(582) : eval()’d code on line 9; PHP message: PHP Fatal error: Uncaught Error: Call to a member function get() on null in /mysite.ru/wp-content/plugins/code-snippets/php/snippet-ops.php(582) : eval()’d code:13

    I suppose that the error could be in snippet code. Here is it from line 9:

    if ( WC()->cart->total > 250000 ) {
    unset( $available_gateways['cod'] );
    unset( $available_gateways['tbank'] );
    }

    What’s wrong?

    Regards, Alex

Viewing 2 replies - 1 through 2 (of 2 total)
  • Imagepauserratgutierrez

    (@pauserratgutierrez)

    Hi @astahov006

    You’re absolutely right that the error seems to be coming from the snippet you’ve added. The issue could lie in the fact that WC()->cart is null at the time the snippet is executed. This could happen when WooCommerce hasn’t fully initialized the cart object yet.

    To resolve it, consider the following:

    1. Check if WC()->cart is not null: Before accessing WC()->cart->total, add a check to ensure that the cart object is initialized and not null.
    2. Use appropriate WooCommerce filters: Ensure your snippet is hooked into the correct WooCommerce lifecycle events so the cart and payment gateways are properly loaded when your snippet runs.
    3. Debug the cart total property: Instead of directly accessing WC()->cart->total, you might want to check other related properties like cart_contents_total or debug WC()->cart to understand its state when the snippet executes.

    By addressing these points, your snippet should work without triggering errors.

    Best regards,
    Pau.

    Thread Starter Imageastahov006

    (@astahov006)

    Many thanks, Pau

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

The topic ‘error in snippet-ops.php’ is closed to new replies.