1

How can I remove a 3rd Party field for non logged in visitors? It is placed in the billing section, but can't accessed with unset code.

This is rendered in the checkout page:

<p class="form-row aelia_wc_eu_vat_assistant vat_number update_totals_on_change address-field form-row-wide" id="vat_number_field" data-priority="250"><label for="vat_number" class=""><strong>VAT number</strong>&nbsp;<span class="optional">(optional)</span></label><span class="woocommerce-input-wrapper"><input type="text" class="input-text " name="vat_number" id="vat_number" placeholder="VAT Number" value="" valid="0" aria-describedby="vat_number-description"><span class="description" id="vat_number-description" aria-hidden="true">Only for Retailers: Enter your EU VAT Number (if any). Country prefix is not required.</span></span></p>

I don't want to use javascript based solution cause of caching.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
cysus
  • 143
  • 1
  • 12

2 Answers2

0

I'm not quite sure which portion of the output you want to hide... Have your tried with display:none?

something like:

.form-row{ display:none; }

jacauc
  • 31
  • 4
  • Would be good to see the encapsulating code just before the `

    ` tag. You may be able to do `display:none` on the entire `div` or `span` 's class directly before the `p` tag

    – jacauc Dec 19 '18 at 10:19
  • I could try the css solution. How to do in functions.php in a logged in check? if ( is_user_logged_in() ) { // your code for logged in user } else { // your code for logged out user } – cysus Dec 19 '18 at 10:32
  • I believe most themes will add a `logged-in` class to the body for logged in users. – jacauc Dec 19 '18 at 10:44
  • you could then use `.logged-in .form-row { display:none}` – jacauc Dec 19 '18 at 10:45
0

Updated: You can use the following dedicated filter hook to hide that field from unlogged users:

add_filter( 'wc_aelia_eu_vat_assistant_show_checkout_field_vat_number', 'hide_vat_field_for_unlogged_users', 10, 2 ); 
function hide_vat_field_for_unlogged_users( $show_field, $is_field_required ) {
     if ( ! is_user_logged_in() ) 
         $show_field = false;

     return $show_field
}

Code goes in function.php file of your active child theme (or active theme). It should works.

Note: Old hook wc_aelia_eu_vat_assistant_show_vat_field is obsolete and replaced.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399