I am wondering if there is a way to remove the checkbox "Ship to a different address?" in woocommerce checkout page, but keep the shipping fields visible. I have tried:
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false');
It works, however it won't show any field in the "shipping field tab".
My Answer:
To make WooCommerce checkout shipping fields visible and remove any unnecessary fields, you can use the following code snippet in your theme's functions.php file:
php
// Make shipping fields visible on checkout page
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_first_name']['required'] = true;
$fields['shipping']['shipping_last_name']['required'] = true;
$fields['shipping']['shipping_address_1']['required'] = true;
$fields['shipping']['shipping_city']['required'] = true;
$fields['shipping']['shipping_postcode']['required'] = true;
$fields['shipping']['shipping_country']['required'] = true;
$fields['shipping']['shipping_state']['required'] = true;
return $fields;
}
// Remove unnecessary shipping fields
add_filter( 'woocommerce_checkout_fields', 'custom_remove_checkout_fields' );
function custom_remove_checkout_fields( $fields ) {
unset( $fields['shipping']['shipping_company'] );
unset( $fields['shipping']['shipping_address_2'] );
return $fields;
}
This code will make the shipping fields required and remove the shipping company and address line 2 fields from the WooCommerce checkout page. You can customize this code further to suit your specific requirements.
Rate this post
5 of 5 based on 8669 votesComments