• Hi,

    I am trying to remove vat field and self certification feature if carts total is 0.
    0$ is achived with a deduction coupon.
    My client wants free product option with only name, surname and email address.

    So i tried this in functions.php, with no luck:

    
    global $woocommerce;
    if ( 0 != $woocommerce->cart->total ) {
    
    $aelia_euva = Aelia\WC\EU_VAT_Assistant\WC_Aelia_EU_VAT_Assistant::instance();
    remove_action('woocommerce_checkout_billing', array($aelia_euva, 'woocommerce_checkout_billing'), 40);
    
    }

    Same logic in checkout-self-certification-field.php and checkout-eu-vat-field.php removes fields. But I want to do it in an elegant way ??

    Another problem is that after removing these functions from the cart, certification validation is still active and stops order from completition.

    Can you please guide me with the solution ?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Diego

    (@daigo75)

    At the moment, I’m afraid that isn’t a an elegant solution that is also easy to implement. The fields were not designed to be added or removed dynamically from the page structure using filters, as the assumption was that customer is required to complete the billing information regardless of the content of the cart (i.e. even when the cart total is zero).

    You might want to try hiding the fields via JavaScript, instead of using filters. The selectors are, respectively:
    – VAT field: $('#vat_number')
    – Self certification field: $('#woocommerce_location_self_certification')

    If you detect that the cart total is zero, you can apply a custom CSS class to hide them. If the total increases, then you can remove the CSS class.

    Thread Starter Mastafu Design

    (@mastafu)

    Hi,

    I got no problem with hiding these 2 fields. I got problem with processing order. Your vat field validation stays on, even if I remove vat fields with php.

    That is my problem, can you sugest solution to this problem ?

    Plugin Author Diego

    (@daigo75)

    The VAT field is not really designed to be removed via PHP. The solution I suggested hides the fields via JavaScript, so that they are still there, just hidden. With this approach, the fields will be posted to the backend on checkout, and the validation will find them (empty) and move on. You will just have to keep in mind to set the VAT number field as “optional”, so that the validation won’t complain that the field is empty.

    Note
    If you set the VAT number to be “required” (see https://prntscr.com/e071ha), then it will be required when the conditions are met, no matter what the cart amount is. There is no such option as “make VAT number required only when the cart amount is greater than zero“.
    If you need to implement your own custom logic to make the VAT number required, you can use filter wc_aelia_euva_order_is_eu_vat_number_required. It takes two parameters:
    – $required – Indicates if the VAT number is required.
    – $customer_country – Customer’s billing country.

    In your filter, you can do what you like to decide if the VAT number should be required, and return true or false, as needed.

    If you need help implementing a customisation for your specific requirements, you can use our contact form to get in touch. We will review your specifications and get back to you with an estimate for the implementation.

    Hi mastafu,

    did you found a solution for your problem? Can you share it here?

    Plugin Author Diego

    (@daigo75)

    @arigold23 toe be precise, that’s not a problem, but a customisation. ??

    If you need a template for the filter, to get started, you should be able to use this one:

    /**
     * Sets the VAT number field as "not required" when the cart total is zero (or
     * less; which should never happen, but better to cover that case).
     *
     * @param bool is_vat_number_required Indicates if the VAT number is required.
     * @param string country The billing country selected at checkout.
     * @return bool
     */
    add_filter('wc_aelia_euva_order_is_eu_vat_number_required', function($is_vat_number_required, $country) {
      // Make VAT number "not required" if the cart total is zero
      if(WC()->cart->total <= 0) {
        $is_vat_number_required = false;
      }
    	
      return $is_vat_number_required;
    }, 10 2);
    • This reply was modified 7 years, 10 months ago by Diego. Reason: Added code example
    • This reply was modified 7 years, 10 months ago by Diego.
    • This reply was modified 7 years, 10 months ago by Diego.
    Thread Starter Mastafu Design

    (@mastafu)

    Looks promising but after adding this to functions, checkout renders empty page.

    Could you check it one more time ?
    And maybe add /modify code pasted in the beginning of this post ?
    This would create elegant function to remove vat validation and fields for cart less then 0.

    
    global $woocommerce;
    if ( 0 != $woocommerce->cart->total ) {
    
    $aelia_euva = Aelia\WC\EU_VAT_Assistant\WC_Aelia_EU_VAT_Assistant::instance();
    remove_action('woocommerce_checkout_billing', array($aelia_euva, 'woocommerce_checkout_billing'), 40);
    
    }
    
    Plugin Author Diego

    (@daigo75)

    It looks like my example is missing a comma. Small oversight, here’s the fixed code:

    /**
     * Sets the VAT number field as "not required" when the cart total is zero (or
     * less; which should never happen, but better to cover that case).
     *
     * @param bool is_vat_number_required Indicates if the VAT number is required.
     * @param string country The billing country selected at checkout.
     * @return bool
     */
    add_filter('wc_aelia_euva_order_is_eu_vat_number_required', function($is_vat_number_required, $country) {
      // Make VAT number "not required" if the cart total is zero
      if(WC()->cart->total <= 0) {
        $is_vat_number_required = false;
      }
    	
      return $is_vat_number_required;
    }, 10, 2);

    Regarding your implementation, I’m afraid that your code might not work. As I wrote already, you should not remove the field via PHP, as that can cause issues. That approach is not a supported solution, and we would not recommend to use it.

    You might want to have a look at an article we posted today on the topic: WooCommerce EU VAT Assistant – Make VAT number optional when cart total is zero. It shows how to make the VAT number optional without hacking the page rendering.

    • This reply was modified 7 years, 10 months ago by Diego.
    • This reply was modified 7 years, 10 months ago by Diego.
    Thread Starter Mastafu Design

    (@mastafu)

    Looks promising but still has no effect.

    Errors in the console.
    TypeError: data is undefined [More info] checkout:487:10

    1. Step 1 – filter woocommerce_update_order_review_fragments, adde to functions
    2. Step 2 – Get the cart total from the fragments, via JavaScript
    a. there is <?php missing in the beginning
    3. Step 3 added to the functions.

    Plugin Author Diego

    (@daigo75)

    The code is correct, I just checked it. The <?php tag is not missing, it’s not supposed to be there in the first place. ??

    Probably it’s easier if you take the code from the Pastebin at the bottom of the article. Just keep in mind that the article is a proof of concept, to show one way how the result can be achieved. It’s not a guaranteed and complete solution to cover all cases, you might have to adapt it to your needs. ??

    Thread Starter Mastafu Design

    (@mastafu)

    Is that proof of concept tested on actual WP + Woo installation by You?

    Plugin Author Diego

    (@daigo75)

    Yes. We tested on our development servers, on sites with WordPress, WooCommerce and EU VAT Assistant, it works fine. It’s marked as a “proof of concept” because it was written to illustrate a possible approach to cover the scenario you described.

    This kind of modification is a customisation, outside the scope of the support service we can provide on this forum. We wrote it as a courtesy, for the benefit of anyone who might need it, so that they can use it as a starting point and tailor it to their specific needs.

    • This reply was modified 7 years, 10 months ago by Diego.
    Thread Starter Mastafu Design

    (@mastafu)

    Thank you Diego.
    Quite frankly adding this as an option in your plugins setting page, would just make it better.
    There is quite a lot of scenarios in shop related cases where cart can be with 0 price ??

    Plugin Author Diego

    (@daigo75)

    As I explained, that scenario is outside the scope of the plugin. The purpose of the “VAT Number required” option is to always make it required, to enforce B2B transactions.
    If a digital product is free, it can make more sense to provide a direct link to it, rather than having customers place an “order” where they don’t have to pay anything.

    As for physical products, the EU VAT Assistant can deal with them, but it was not designed for them. It’s a plugin developed with the specific purpose of helping with the compliance with the EU VAT MOSS regulations, which affect only sales of digital products.

    As we demonstrated, it’s is flexible and customisable solution, but it’s not meant to be a universal VAT management system (if it were, it would most likely have more features, and a price tag). ??

    I can add your idea to the feature list, but we can’t guarantee that it will be implemented. The EU VAT Assistant is working as intended, covering the requirements for which it was designed.

    We tend not to add more features, unless required by regulations, or commissioned as a paid customisation, as each feature means more maintenance.

    Unfortunately, we can’t provide a free plugin with free support and free customisations. If you or your client wish to sponsor that feature, please feel free to get in touch, and we will provide an estimate for it.

    Thread Starter Mastafu Design

    (@mastafu)

    I appreciate your hard work, we both now how this business works. Free plugins / paid versions, but ??

    If woocommerce allows for a free product, which it does. Your plugin should be able to hande it. And it doesn’t right now.
    Especially right now, when you have everything prepared. Problem mentioned, solution ready. Adding it should be quite easy, even not as a option. Rather as an fix. Your plugin should automatically disable itself, once carts total is 0.

    Plugin Author Diego

    (@daigo75)

    I respectfully disagree. What you describe is not a bug, nor a problem, but a customisation. If you choose to make the VAT number required, then you must keep in mind that are making it always required, and that’s by design. If you wish to make it required in specific circumstances, we showed how you can do so, so your custom scenario of “cart with zero total” can also be supported.

    The EU VAT Assistant might not fulfil your exact needs, but it’s working as intended (and, as demonstrated, you can customise it as you like). If the feature you need will make it in a future version, even better, but we can’t make promises about it.

    • This reply was modified 7 years, 10 months ago by Diego.
    • This reply was modified 7 years, 10 months ago by Diego.
    • This reply was modified 7 years, 10 months ago by Diego.
Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Remove VAT field and self certification for Cart total = 0’ is closed to new replies.