Hi @fredrikvestin
but when choosing PayPal it opens the PayPal window without giving the notice?
That is because the PayPal plugin and integration is different and not comparable to how Stripe works. When you click the PayPal payment button, the checkout form isn’t being submitted yet. The checkout form is only submitted after the customer completes the payment in the PayPal popup window. You have two approaches you can take for this:
- On the PayPal Settings page you can enable the option
Use Place Order Button
. When enabled, the plugin uses the Place Order button, rather than rendering separate PayPal payment buttons. That will trigger your custom validation because the WooCommerce Checkout validations are triggered, and then the customer is redirected to PayPal.
- You can continue to use the PayPal buttons on your checkout page, and implement action
wc_ppcp_checkout_validation
. That action allows you to perform validations when using the PayPal payment buttons. Make sure you have the option Validate Checkout Fields
enabled via the Advanced Settings page. Here is an example of how to use this action:
add_filter('wc_ppcp_checkout_validation', function($validator, $request){
if(!$request->get_param('custom_field')){
$validator->add_error('Custom field is required to proceed');
}
}, 10, 2);
Kind Regards