Skip to content

Instantly share code, notes, and snippets.

@wplaunchify
Forked from ajmorris/functions.php
Created February 24, 2020 05:55
Show Gist options
  • Save wplaunchify/2df82e777e3eb4b4be1a43eeb552ef9b to your computer and use it in GitHub Desktop.
Save wplaunchify/2df82e777e3eb4b4be1a43eeb552ef9b to your computer and use it in GitHub Desktop.
Remove checkout field if product IDs exist. WooCommerce / WordPress
<?php
/**
* Conditionally remove a checkout field based on products in the cart
*/
function wc_ninja_remove_checkout_field( $fields ) {
if ( ! wc_ninja_product_is_in_the_cart() ) {
unset( $fields['billing']['billing_company'] );
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'wc_ninja_remove_checkout_field' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment