I need to hide the payment by credit card when I have a specific coupon such as “tcrfam” and when I use any different to this show the payment by card, the idea is that I do not give a coupon of 100% or free and there is no case I ask credit card data.
I tried this code but dont work:
add_action('woocommerce_before_checkout_form', 'apply_product_on_coupon');
function apply_product_on_coupon() {
global $woocommerce;
$coupon_id = 'tcrfam';
if(in_array($coupon_id, $woocommerce->cart->get_applied_coupons())){
echo "Yes the coupon its inserted dd";
add_filter( 'woocommerce_cart_needs_payment', '__return_false' );
}
}
I need to use add_filter (‘woocommerce cart needs payment’, ‘__return_false’); within the function as in the code above but I don’t know how to do it, can someone give me an idea of how to do it? Thank you
2
Answers
The code that you needs should be in the filter hook directly, like:
Code goes in functions.php file of your active child theme (or active theme). It should works.
I found this snippet very useful for me, but I’ve a question … if the coupon codes for disable the methods payment are more than one? Can I use?
I tried it, but Woocommerce is not asking me the payment method for every coupon code and not fot only the 2 that I wrote.
Thanks in advance