Modify listing manual approval PHP snippet dont work

Hello, I am usint Taskhive and trying to add 2 PHP function, but both don’t work. I suspect that I am doing something elementary wrong. Any addvice would be really appreciated.

  • I wrote Appearance>Thema file Editor>function.php of Taskfive and children Thema, but both don’t work.
    -I add PHP via Plugin “Code Snippets”, but dose not work.

The 2 PHP I tried,

add_filter( 'woocommerce_checkout_fields' , 'bbloomer_simplify_checkout_virtual' );
 
function bbloomer_simplify_checkout_virtual( $fields ) {
    
   $only_virtual = true;
    
   foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
      // Check if there are non-virtual products
      if ( ! $cart_item['data']->is_virtual() ) $only_virtual = false;   
   }
     
    if( $only_virtual ) {
       unset($fields['billing']['billing_company']);
       unset($fields['billing']['billing_address_1']);
       unset($fields['billing']['billing_address_2']);
       unset($fields['billing']['billing_city']);
       unset($fields['billing']['billing_postcode']);
       unset($fields['billing']['billing_country']);
       unset($fields['billing']['billing_state']);
       unset($fields['billing']['billing_phone']);
       add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
     }
     

     return $fields;
}

Hi,

As for this PHP snippet Modify listing manual approval - #8, it works if you use the Code Snippet plugin How to add custom code snippets - HivePress Help Center. Also, please disable third-party plugins and customizations (if there are any) and check if this issue persists. If you use a caching plugin, make sure that caching is disabled for logged-in users.

Regarding your second PHP snippet, unfortunately, we can’t help you as it is out of our scope. We recommend contacting WooCommerce support or checking their documentation.

Hello,

If I’ve understood the purpose of this discussion correctly, you’re looking to edit or remove Woocommerce checkout fields ?

If so, you may be interested in the following information.

To edit or remove Woocommerce checkout fields, you can use the snippet code I found in the following sources :
-. developer.woocommerce.com - Customizing checkout fields using actions and filters
-. How to Customize Woocommerce Checkout page? 31 useful hacks
-. www.codesnippets.cloud - Deactivate some WooCommerce Checkout Fields

Unfortunately, I can’t get it to work on my own Woocommerce checkout fields. So if it ever works for you, please let me know.

Here’s the snippet code I used :

/* WooCommerce: The code below deletes the checkout fields */
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
// Remove checkout fields
function custom_override_checkout_fields( $fields ) {
 // remove billing fields
    unset($fields['billing']['billing_first_name']); // Billing First name
    unset($fields['billing']['billing_last_name']); // Billing Last name
    unset($fields['billing']['billing_company']); // Billing company
    unset($fields['billing']['billing_address_1']); // Billing Address 1
    unset($fields['billing']['billing_address_2']); // Billing Address 2
    unset($fields['billing']['billing_city']); // Billing city
    unset($fields['billing']['billing_postcode']); // Billing postcode
    unset($fields['billing']['billing_country']); // Billing country
    unset($fields['billing']['billing_state']); // Billing state
    unset($fields['billing']['billing_phone']); // Billing phone
    unset($fields['billing']['billing_email']); // Billing email
   
    // remove shipping fields 
    unset($fields['shipping']['shipping_first_name']); // Shipping first name  
    unset($fields['shipping']['shipping_last_name']); // Shipping last name  
    unset($fields['shipping']['shipping_company']); // Shipping company  
    unset($fields['shipping']['shipping_address_1']); // Shipping address 1
    unset($fields['shipping']['shipping_address_2']); // Shipping address 2
    unset($fields['shipping']['shipping_city']); // Shipping city 
    unset($fields['shipping']['shipping_postcode']); // Shipping postcode
    unset($fields['shipping']['shipping_country']); // Shipping country
    unset($fields['shipping']['shipping_state']); // Shipping state
    
    // remove order comment fields
    unset($fields['order']['order_comments']); // Order comments
     return $fields;
}

But if you want to edit or remove Woocommerce checkout fields without using PHP code, you can use the (paid but official) Woocommerce plugin : woocommerce.com - Order Validation Fields Editor

Or you can use the following free (freemium) plugins:
-. Checkout Field Editor (Checkout Manager) for WooCommerce
-. Fluid Checkout for WooCommerce - Lite

Hi Andrii,
Thank you very much your kind replying! I tried the PHP on the page Modify listing manual approval - #8 , but it doesn’t work with both Code Snippet plugin and functions.php. I switch off all the third party plugin and clear the cash, but it doesn’t help.

Whatelse can I try?

Hello Valentin.M,
Thank you very much for your advice. Yes, I would like to remove an address field on Woocommerce chekout page.

I wrote different type of PHP on function.php and tried with Code Snippets plugin, but unfortunately both do not work :frowning:

Hi,

Please provide more details regarding this issue (e.g., your actions step by step with screenshots, etc.). This will help us to reproduce and resolve the issue faster.

Hi,

I attached the screenshot to add PHP on functions.php. I could approve it correctly. However, when I change listing-title as vendor, it requires to manually modify by admin.

It is not convenient for vendors to need admin authentication every time they want to update the content of a listing.

Hello.
About “Remove ‘street address’ and ‘postal/zip’ options in the checkout page”, PHP works when I use a shortcode instead of block on the checkout page.

It seems like this problem will be solved next month on the Roadmap “Fix compatibility with the new WooCommerce checkout block”.