Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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>';
    }
}
Comment

remove fields woocommerce checkout wordpress

WooCommerce Checkout Fields Manager:
https://wordpress.org/plugins/woocommerce-checkout-manager/

WooCommerce direct checkout:
https://wordpress.org/plugins/add-to-cart-direct-checkout-for-woocommerce/
Comment

PREVIOUS NEXT
Code Example
Php :: like button phpAdd Answer 
Php :: laravel collection makeHidden 
Php :: italic text in laravel notification 
Php :: symfony request type 
Php :: create config value file in php 
Php :: php fake stripe client 
Php :: Remove the Breadcrumb on the Shop Page 
Php :: uft8 json php 
Php :: php namespaces 
Php :: remove some state from state list woocommerce 
Php :: windows list registered applications 
Php :: Trying to access variable outside laravel collection 
Php :: Uncaught Error: Call to undefined function add_submenu_page() 
Php :: apt-get install php wordpress extensions 
Php :: get custom field post wordpress dev 
Php :: php change get value in a link 
Php :: morph relation laravel 
Php :: warning: parameter 2 to search_by_title() expected to be a reference, value given inwp-includesclass-wp-hook.php on line 287 
Php :: php infinite loop 
Php :: php check if type is mysqli_result 
Php :: $faker-paragraph 
Php :: drupal show php errors 
Php :: Laravel unique with Validation with multiple input value 
Php :: livewire check no errors 
Php :: php link 
Php :: how to add custom navigation menus in wordpress themes 
Php :: get current month laravel 
Php :: php 8 null safe operator 
Php :: delete a migration laravel 
Php :: php = 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =