Hi @nilesh6018
these fields are not validated before the payment is processed.
That is not a correct statement. The payment is never processed until all required fields are validated since WooCommerce performs a server side validation of all required fields before the plugin is called.
Also, the payment is not finalized when the PayPal popup is visible. Payment finalization occurs server side after the checkout form submits.
Can you please help me to fix this issue as soon as possible?
Can you share what custom code you wrote using filter wc_ppcp_checkout_validation_fields
? If written correctly, that should be all you need to properly trigger the validation.
Did you make sure to turn on field validation via the Advanced Settings page of the PayPal plugin?
Kind Regards
Thank you for your prompt replay,
We are use additional WooCommerce fields just before Place order button, does this field validate before I place an order using PayPal method?
add_action('woocommerce_review_order_before_submit', 'display_country_based_checkbox');
function display_country_based_checkbox() {
woocommerce_form_field( 'conformation', array(
'type' => 'checkbox',
'class' => array('form-row conformation'),
'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'),
'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
'required' => true,
'label' => 'Der Versand von durchgeführten Tests aus anderen Ländern nach Deutschland erfolgt auf die Kosten der Kundin. Der Betrag kann je nach Land abweichen.',
));
}
also I validate field using this method
add_action('woocommerce_checkout_process', 'validate_country_checkbox_field');
function validate_country_checkbox_field() {
// Get the posted value of the checkbox
$checkbox_value = isset($_POST['conformation']) ? $_POST['conformation'] : '';
wc_add_notice(__('Der Versand von durchgeführten Tests aus anderen Ländern nach Deutschland erfolgt auf die Kosten der Kundin. Der Betrag kann je nach Land abweichen.'), 'error');
}
-
This reply was modified 6 months, 2 weeks ago by
nilesh6018.
Hi @nilesh6018
In your OP you said you were using filter wc_ppcp_checkout_validation_fields
. Please share the custom code you wrote for that filter.
does this field validate before I place an order using PayPal method?
No, you haven’t told WooCommerce that field exists and that it should be validated. The proper filter to tell WooCommerce to validate your field is woocommerce_checkout_fields
.
But you don’t need to use woocommerce_checkout_fields
if you use the PayPal plugin filter correctly. I personally think wc_ppcp_checkout_validation
is the best filter for you to use.
Kind Regards
Than you for the clarification can you please provide me an example with the use of ” wc_ppcp_checkout_validation “?
I will try from my side and I will let you know if I face an issue after use the ” wc_ppcp_checkout_validation “.
add_action('wc_ppcp_checkout_validation', function($validator, $request){
if(empty($request['conformation'])){
$validator->add_error('Conformation checkbox is a required field.');
}
}, 10, 2);