"woocommerce unset custom checkout field" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "woocommerce unset custom checkout field" answered properly. Developers are finding an appropriate answer about woocommerce unset custom checkout field related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like woocommerce unset custom checkout field. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on woocommerce unset custom checkout field.
woocommerce unset custom checkout field
// Conditional function: If one of the special products is in cart return true, else false
function is_in_cart() {
// Add your special product IDs here
$ids = array( 45, 70, 75 );
foreach( WC()->cart->get_cart() as $cart_item ){
$product_id = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->id : $cart_item['data']->get_id();
if( in_array( $cart_item['data']->get_id(), $ids ) )
return true;
}
return false;
}
add_filter( 'woocommerce_checkout_fields' , 'remove_checkout_fields', 10, 1 );
function remove_checkout_fields( $fields ) {
if( ! is_in_cart() )
unset($fields['billing']['billing_company']);
return $fields;
}
add_action( 'woocommerce_after_order_notes', 'company_details_section', 10, 1 );
function company_details_section( $checkout ){
// Here your conditional function
if( is_in_cart() ){
echo '<div id="my_custom_checkout_field"><h3>' . __('Company Details') . '</h3>';
woocommerce_form_field( 'delegate_1_name', array(
'type' => 'text',
'class' => array( 'my-field-class form-row-wide delegateExists' ),
'label' => __('Full name') ,
) , $checkout->get_value( 'delegate_1_name' ) );
echo '</div>';
}
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on woocommerce unset custom checkout field can get a collection of related answers to their query. Programmers need to enter their query on woocommerce unset custom checkout field related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about woocommerce unset custom checkout field for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of woocommerce unset custom checkout field while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "woocommerce unset custom checkout field". Visit this developer's friendly online web community, CodeProZone, and get your queries like woocommerce unset custom checkout field resolved professionally and stay updated to the latest Whatever updates.