hiding for specif cat

PHOTO EMBED

Sat Jan 28 2023 18:56:20 GMT+0000 (Coordinated Universal Time)

Saved by @itaiki

/*hiding for specif cat*/
add_filter( 'woocommerce_checkout_fields', 'conditionally_remove_checkout_fields', 25, 1 );
function conditionally_remove_checkout_fields( $fields ) {

    // HERE the defined product Categories
    $categories = array('no-choose');

    $found = false;

    // CHECK CART ITEMS: search for items from our defined product category
    foreach ( WC()->cart->get_cart() as $cart_item ){
        if( has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) {
            $found = true;
            break;
        }
    }

    // If a special category is in the cart, remove some shipping fields
    if ( $found ) {

        // hide the billing fields
        //unset($fields['shipping']['shipping_first_name']);
        //unset($fields['shipping']['shipping_last_name']);
        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']);
		unset($fields['billing']['order_birthday_date']);
		unset($fields['billing']['billing_address_apartment_passcode']);
		unset($fields['billing']['order_anniversary_date']);
		unset($fields['billing']['billing_address_floor_number']);
		unset($fields['billing']['billing_apartment']);
		unset($fields['billing']['city_dropdown']);
		
        // hide the additional information section
        add_filter('woocommerce_enable_order_notes_field', '__return_false');
        add_filter( 'woocommerce_ship_to_different_address_checked', '__return_false' );
    }
    return $fields;
}
content_copyCOPY