Hi there,
Thanks for reaching out.
We usually don’t provide support for custom snippets, but I’ll make an exception here as it’s relatively a quick one to add. Can you please try to replace the previous code with the following one:
add_filter( 'woocommerce_available_payment_gateways', 'show_hide_payment_methods' );
function show_hide_payment_methods( $available_gateways ) {
if ( WC()->cart->total > 200 ) {
if ( isset($available_gateways['cod']) ) {
unset($available_gateways['cod']);
}
}
return $available_gateways;
}
Let me know how it goes!
Best,
Hi,
Thank you very much for your help and for how fast you answered to my issue.
Unfortunately, the error remains. The line with the error in your code is this:
if ( WC()->cart->total > 200 ) {
And in my code is this:
$cart_total = $woocommerce->cart->total;
That’s why I thought that maybe something changed in your files for the “total” property.
I’m searching all day in woocommerce folders but I can’t find something.
Hello @xrisa30!
I tested the code that Daniyal shared before and found it to be working properly.
I suggest you do a conflict test to find whether the issue is coming from your theme/other plugin/other custom codes.
You can find a more detailed explanation of how to do a conflict test here. → https://docs.woocommerce.com/document/how-to-test-for-conflicts/
Before you start
Please make sure you have a good backup in place of your full site and database. Most hosting companies have this included in the subscription, but you could also consider using a service like Jetpack. If something goes wrong, it’s nice to know that you can restore your site.
Let us know how it goes.
Hi guys,
Both codes (mine and Daniyal’s) working fine but the error in the logs remains. 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.php
if ( 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 tried in my localhost to do some debug and it seems that this error is from wpocean theme.
So, I will let them know.
Thanks both of you for your help.
Xrisa
Hi @xrisa30!
I am happy to hear that you figured it out, let us know how it goes!
All the best,