• Resolved gerold1968

    (@gerold1968)


    Hi, I am getting these warnings:

    Got error ‘PHP message: PHP Warning: Attempt to read property “total” on null in /wp-content/plugins/code-snippets/php/snippet-ops.php(581) : eval()’d code on line 17

    Any ideas? Thanks Gerold

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi @gerold1968,

    Could you share the code snippet so I can try to understand why is this happening?

    Thread Starter gerold1968

    (@gerold1968)

    Hi, thanks for quick reply!

    I found this warning in server protocol. It doesn′t seem it is connected to a snippet, but the plugin code, don′t you think?

    Best Gerold

    Hi @gerold1968,

    I’m not sure, that is why I would like to take a look at the code snippet to see if this warning comes from it. Please note that I’m not part of the developers of this plugin, but also an user, like you ??

    That said, I use this plugin since several years ago, so I think I can find out the solutions for most common issues.

    In your specific case, the notice says that the issue is being produced in the line 17 of one of your code snippets. The mention of the snippet-ops.php is only part of the error trace, since is here where your code snippets are checked to search for possible errors.

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi @gerold1968,

    This error is coming from one of your snippets, not from the plugin. It’s something only you can solve, though if you post the code here, as Yordan suggests, we can see what we can do to help you fix it.

    Thread Starter gerold1968

    (@gerold1968)

    Hi thanks for clarifying. Is there a way to trace down which snippet? I have a bunch of them ??

    I can′t find anything about this in the error message…

    • This reply was modified 1 year, 2 months ago by gerold1968.
    Thread Starter gerold1968

    (@gerold1968)

    Hi again. I think I could nail it down to this code:

    In line 17 it goes:

       $order_total = $order->get_total();

    add_filter( ‘woocommerce_available_payment_gateways’, ‘gerold_disable_cod’ );

    function gerold_disable_cod( $available_gateways ) {

    if( is_admin() ) {
        return $available_gateways;
    }
    
    // STEP 1: Get order/cart total
    if( is_wc_endpoint_url( 'order-pay' ) ) { // Pay for order page
    
        $order_id = wc_get_order_id_by_order_key( $_GET[ 'key' ] );
        $order = wc_get_order( $order_id );
       $order_total = $order->get_total();
    
    } else { // Cart/Checkout page
        $order_total = WC()->cart->total;
    }
    
    // STEP 2: Disable COD if order/cart total is less than 250,-
    if ( $order_total < 250 ) {
        unset( $available_gateways[ 'cod' ] ); // unset COD
    }
    
    return $available_gateways;

    }

    • This reply was modified 1 year, 2 months ago by gerold1968.
    • This reply was modified 1 year, 2 months ago by gerold1968.

    Hi @gerold1968,

    I’m glad to hear that you managed to make it work!

    Actually, using the order data has more sense that the cart one, after the order is placed.

    However, as a side note, it seems that WC()->cart->total no longer work.

    To get the cart total, you should try one of these instead:

    WC()->cart->get_total(); // formatted amount $123.99 
    WC()->cart->get_total( 'edit' ); // unformatted amount 123.99
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘php warning’ is closed to new replies.