0

I am just wondering what would be the if statement if I would like to remove validation from the checkout form when the user picked paypal as a payment option?

I know I can use something like

function not_required_fields( $f ) {


unset( $f['billing']['billing_first_name']['required'] ); // that's it
unset( $f['billing']['billing_phone']['required'] );

return $f;
}

but I would need to know the if statement before such as

if(payment_method == PayPal)
{

above code here

}

The only thing is that I have no idea how I would write it in woocommerce

KeDeN
  • 105
  • 11
  • 1
    This will not work as selecting a payment method is a live event on client side… So first you need to make those checkout fields ***not required*** by default. Then additional jQuery code is required to make that fields appear as required when Paypal is not selected and finally a php conditional validation function hooked in `woocommerce_checkout_process` hook, when the chosen payment gateway is not Paypal. Now you can search in this [related answers](https://stackoverflow.com/search?tab=newest&q=%5bwoocommerce%5d%5bjquery%5d%5bcheckout%5d%20payment) and some others… – LoicTheAztec Jul 10 '18 at 13:46
  • can you give me sample code for jquery when paypal is not selected? and also php conditional validation function. – KeDeN Jul 11 '18 at 10:21
  • You have a lot of samples in StackOverFlow actually, so you just need to search, to try making the necessary changes regarding your specific checkout payment gateways. Once you will have something viable, if you have problems, you will ask in stackOverFlow. In my first comment you have everything to make it yourself. If you are not able, you should hire someone enough skilled for that. – LoicTheAztec Jul 11 '18 at 10:53
  • 1 sample code: [show-hide-based-on-payment-method](https://stackoverflow.com/questions/54927919/show-hide-custom-woocommerce-checkout-field-based-on-selected-payment-method#answer-54930369) (28 Feb 2019) – contemplator Dec 31 '20 at 00:06

0 Answers0