Conflict with WC
-
Hi guys,
I have a code in my child functions for set maximum total amount for COD. My code is this:
function xr_limit_cod_gateway( $available_gateways ) { global $woocommerce; $cart_total = $woocommerce->cart->total; if ( isset( $available_gateways['cod'] ) && $cart_total > 200) { unset( $available_gateways['cod'] ); } return $available_gateways; } add_filter( 'woocommerce_available_payment_gateways', 'xr_limit_cod_gateway' );
The code works fine but in my logs I can see an error says:
Notice: Trying to get property ‘total’ of non-object in wp-content/themes/oceanwp-child-theme-master/functions.php on line …
This line is the following:
if ( WC()->cart->total > 200 ) {
I contacted WC support and here you can see the ticket with our conversation:
https://www.ads-software.com/support/topic/error-in-property/#post-15660934
I did some debugs in my localhost and I found that this is caused by ocean theme.
Here are the steps that I followed to replicate the issue:
1. Back up and duplicate all the entire live site in my localhost so they have the same settings.
2. All my plugins and the theme are in the latest version.
3. Deactivate all the plugins except WC.
4. Put the code in ocean child theme functions.php
5. Go to frontend, add some items in my cart and refresh the cart.
6. Now I can see the error in my debug logs.
7. Remove the code from ocean child theme functions.php
8. Now the error stops.
9. Activate twenty sixteen.
10. Put the code in twenty sixteen theme functions.php
11. Go to frontend, add some items in my cart and refresh the cart.
12. No error in my debug logs and the code works as it should.As you can read in my ticket in WC support, the thing is that this error probably cause another error.
The last times I tried to update WC it doesn’t let the database to be updated and it caused the site to get down.
Every time I have to remove this code in note.phpif ( empty( $label ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'woocommerce' ) ); }
After this I update again the database and put again the code back.
I think that the issue with the database update it happens because of this issue.
Can you check it and help me understand what is happening? What are your thoughts about it? I find it very strange.
Thank you
Xrisa
- The topic ‘Conflict with WC’ is closed to new replies.