Issue with VAT Field Validation in WPFunnels checkout when using FakturaXL plug
-
Hello,
I have such a problem:
I created a special php snippet that validates one of the fields added with the Checkout Field Editor for WooCommerce (Pro) plugin in the checkout form (WPFunnels plugin sees these fields in its checkout). In Poland, additional fields “company name” and NIP (VAT) are needed for invoicing, so I had to add them (and it is the NIP (VAT) field that validates my snippet).
The snippet is presented as follows:
add_filter('woocommerce_checkout_posted_data', 'sanitize_and_validate_billing_vat_number');
function sanitize_and_validate_billing_vat_number($data)
{
// Checks that the checked checkbox field named “billing_vat_on” exists and has a value of true, and that the NIP (VAT) field is not empty
if(isset($_POST['billing_vat_on']) && $_POST['billing_vat_on'] && !empty($data['billing_vat_number'])){
$billing_vat_number = $data['billing_vat_number'];
// Removes spaces and hyphens from the NIP (VAT) number
$billing_vat_number = str_replace([' ', '-'], '', $billing_vat_number);
// Checks if the NIP (VAT) number has 10 digits
if (preg_match('/^[0-9]{10}$/', $billing_vat_number) == false) {
wc_add_notice(__('<strong>Podany numer NIP jest niepoprawny.</strong> Wpisz polski numer NIP bez spacji i myślników.', 'woocommerce'), 'error');
} else {
// Calculates the checksum
$weights = [6, 5, 7, 2, 3, 4, 5, 6, 7];
$sum = 0;
for ($i = 0; $i < 9; $i++) {
$sum += $billing_vat_number[$i] * $weights[$i];
}
$control_number = $sum % 11;
// Checks whether the checksum is correct
if ($control_number != $billing_vat_number[9]) {
wc_add_notice(__('<strong>Podany numer NIP jest niepoprawny.</strong> Wpisz polski numer NIP bez spacji i myślników.', 'woocommerce'), 'error');
} else {
// Saves the filtered value of the field “billing_vat_number”
$data['billing_vat_number'] = $billing_vat_number;
}
}
}
return $data;
}If the customer wants to receive an invoice, he checks the box “I want to receive an invoice” and 2 fields appear for completion: company name and NIP.
I have a dedicated plug-in installed for invoicing (whose name is Woocommerce FakturaXL by WPDesk). This plugin automatically issues invoices when the order status changes to Completed.
The problem is as follows: while on a standard Woocommerce checkout page with the Woocommerce FakturaXL plugin enabled, everything works as expected, the checkout used in a sales funnel created with the WPFunnels plugin does not. To be more precise – the script works and validates NIP (VAT) in the WPFunnels funnel only when I disable the Woocommerce FakturaXL plugin and stops validating when I enable it.
Are you able to solve this problem?
I created the validation to eliminate the problem with misspelled NIP (VAT) already at the checkout stage. Unfortunately, when I enable the FakturaXL plugin, this validation stops working in the WPFunnels sales funnel (which is very important for my sales activities), causing customers to write nonsense in the NIP field, which in turn prevents automatic issuance of documents.
I am using the latest version of all plugins Woocommerce FakturaXL 1.7.0, Woocommerce 9.1.2, WPFUnnels 3.4.7
I am very much asking for help.
The topic ‘Issue with VAT Field Validation in WPFunnels checkout when using FakturaXL plug’ is closed to new replies.