• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Hide a WooCommerce checkout field only on one product

Learn in this tutorial how to hide any field on the checkout page in WooCommerce for a specific product with a simple code snippet.

Are you interested in hiding any checkout field but only for a specific product?

Thanks to WooCommerce’s woocommerce_checkout_fields filter you can achieve this easily.

Here’s how to do it:

Snippet to hide a WooCommerce checkout field on a specific product

Add the following code at the end of functions.php or in your functionality plugin:

To see this and another 847 code snippets of this website, login or subscribe here.

In this case you use the woocommerce_checkout_fields filter along with a conditional where you tell it the product ID (1746, in the example) to remove the field from the second line of the address(billing_address_2).

To adapt it you only have to change the product ID, which is shown when hovering over it.

Product ID

Here’s the list of WooCommerce default fields and how to remove them so you can customize the snippet above to your liking:

// Billing fields
 unset( $fields['billing']['billing_company'] );
 unset( $fields['billing']['billing_email'] );
 unset( $fields['billing']['billing_phone'] );
 unset( $fields['billing']['billing_state'] );
 unset( $fields['billing']['billing_first_name'] );
 unset( $fields['billing']['billing_last_name'] );
 unset( $fields['billing']['billing_address_1'] );
 unset( $fields['billing']['billing_address_2'] );
 unset( $fields['billing']['billing_city'] );
 unset( $fields['billing']['billing_postcode'] );
 // Shipping fields
 unset( $fields['shipping']]['shipping_company'] );
 unset( $fields['shipping']['shipping_phone'] );
 unset( $fields['shipping']['shipping_state'] );
 unset( $fields['shipping']['shipping_first_name'] );
 unset( $fields['shipping']['shipping_last_name'] );
 unset( $fields['shipping']['shipping_address_1'] );
 unset( $fields['shipping']['shipping_address_2'] );
 unset( $fields['shipping']['shipping_city'] );
 unset( $fields['shipping']['shipping_postcode'] );
 // Other
 unset( $fields['order']['order_comments'] );

Conclusion

As you can see, with a few lines of code you can hide the field you want on the WooCommerce checkout page only for a specific product.

If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.

Benefits of being a subscriber. 🙂

PHP WooCommerce

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?