Title: php warning
Last modified: September 21, 2023

---

# php warning

 *  Resolved [gerold1968](https://wordpress.org/support/users/gerold1968/)
 * (@gerold1968)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/php-warning-453/)
 * 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)

 *  [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * (@yordansoares)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/php-warning-453/#post-17069749)
 * Hi [@gerold1968](https://wordpress.org/support/users/gerold1968/),
 * Could you share the code snippet so I can try to understand why is this happening?
 *  Thread Starter [gerold1968](https://wordpress.org/support/users/gerold1968/)
 * (@gerold1968)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/php-warning-453/#post-17071240)
 * 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
 *  [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * (@yordansoares)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/php-warning-453/#post-17071301)
 * Hi [@gerold1968](https://wordpress.org/support/users/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](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/php-warning-453/#post-17071337)
 * Hi [@gerold1968](https://wordpress.org/support/users/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](https://wordpress.org/support/users/gerold1968/)
 * (@gerold1968)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/php-warning-453/#post-17071522)
 * 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 2 years, 6 months ago by [gerold1968](https://wordpress.org/support/users/gerold1968/).
 *  Thread Starter [gerold1968](https://wordpress.org/support/users/gerold1968/)
 * (@gerold1968)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/php-warning-453/#post-17071729)
 * Hi again. I think I could nail it down to this code:
 * In line 17 it goes:
 *     ```wp-block-code
          $order_total = $order->get_total();
       ```
   
 * add_filter( ‘woocommerce_available_payment_gateways’, ‘gerold_disable_cod’ );
 * function gerold_disable_cod( $available_gateways ) {
 *     ```wp-block-code
       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 2 years, 6 months ago by [gerold1968](https://wordpress.org/support/users/gerold1968/).
    -  This reply was modified 2 years, 6 months ago by [gerold1968](https://wordpress.org/support/users/gerold1968/).
 *  [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * (@yordansoares)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/php-warning-453/#post-17076731)
 * Hi [@gerold1968](https://wordpress.org/support/users/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:
 *     ```wp-block-code
       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.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 7 replies
 * 3 participants
 * Last reply from: [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/php-warning-453/#post-17076731)
 * Status: resolved