How Can I override this PHP file ? vendor/magento/module-customer/Model/Vat.php I want to change

const VAT_VALIDATION_WSDL_URL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService?wsdl';


const VAT_VALIDATION_WSDL_URL = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';

How Can I do this in my custom module ?

3 Answers 3


Even though you could override the class and redefine the constant, any other references to that constant in the codebase are still going to get the original value. That's because the object manager isn't involved in the access of the constant. It's being accessed straight from the original class.

I took a look at the Magento 2.3.4 codebase, and luckily it looks like that constant is only used in the Vat::createVatNumberValidationSoapClient() method:

Reference to Vat::VAT_VALIDATION_WSDL_URL constant

You can't make a plugin on that method due to it being protected, but here is what you could do to achieve what you are looking for:

Create Class Preference

<preference for="Magento\Customer\Model\Vat" type="Custom\Module\Model\CustomVat"/>

Overriding Class


namespace Custom\Module\Model;

class CustomVat extends \Magento\Customer\Model\Vat
    const VAT_VALIDATION_WSDL_URL = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';

    protected function createVatNumberValidationSoapClient($trace = false)
        return new \SoapClient(self::VAT_VALIDATION_WSDL_URL, ['trace' => $trace]);

This should do the trick, but keep in mind, this only works because you're also overriding the method that is calling self::VAT_VALIDATION_WSDL_URL, which has the effect of using your overridden value.

Any methods you don't override in the parent Vat class that call self::VAT_VALIDATION_WSDL_URL will return the parent's constant value, not yours.

Also, any references to that constant that might occur from somewhere else in the code base are not going to use your value.


In Magento 2.3.4 theres is bug in VAT valdiate because of change of validtion url of VIES.

Old url is


New one is:


I found this patch: Fixed #27874 Vat Validation URL for EU Vat numbers changed

In this patch there is a solution for change:


I do not have foler app/code/Magento. In my case this file is situated in:


What is the simplest way to apply this patch ? I edited manually Vat.php but there's is no visible changes at all.

  • See my answer for patching vendor folder
    – Joel Davey
    Commented Jun 16, 2020 at 22:26

You can easily patch this file, just change the references to the vendor file and enter this filepath (vendor/magento/module-customer/Model/Vat.php) when prompted.

From faaec185511ccd0d8ca2797c5ea281894522df84 Mon Sep 17 00:00:00 2001
From: Shikha Mishra <[email protected]>
Date: Fri, 17 Apr 2020 22:43:47 +0530
Subject: [PATCH] Fixed #27874 Vat Validation URL for EU Vat numbers changed.

Fixed #27874 Vat Validation URL for EU Vat numbers changed.
 vendor/magento/module-customer/Model/Vat.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/vendor/magento/module-customer/Model/Vat.php b/vendor/magento/module-customer/Model/Vat.php
index 123a9eef4b75..d1144c2e7a66 100644
--- a/vendor/magento/module-customer/Model/Vat.php
+++ b/vendor/magento/module-customer/Model/Vat.php
@@ -44,7 +44,7 @@ class Vat
      * WSDL of VAT validation service
-    const VAT_VALIDATION_WSDL_URL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService?wsdl';
+    const VAT_VALIDATION_WSDL_URL = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
      * Config path to option that enables/disables automatic group assignment based on VAT

create the patch file in my case 27886.patch with the above and run patch < 27886.patch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.