Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('woocommerce_checkout_fields', 'conditionally_remove_checkout_fields', 25, 1);
- function conditionally_remove_checkout_fields($fields)
- {
- $categories = array('house');
- $found = false;
- foreach (WC()->cart->get_cart() as $cart_item) {
- if (has_term($categories, 'product_cat', $cart_item['product_id'])) {
- $found = true;
- break;
- }
- }
- if ($found) {
- unset($fields['shipping']['shipping_first_name']);
- unset($fields['shipping']['shipping_last_name']);
- unset($fields['shipping']['shipping_company']);
- unset($fields['shipping']['shipping_address_1']);
- unset($fields['shipping']['shipping_address_2']);
- unset($fields['shipping']['shipping_city']);
- unset($fields['shipping']['shipping_postcode']);
- unset($fields['shipping']['shipping_country']);
- unset($fields['shipping']['shipping_state']);
- unset($fields['shipping']['shipping_phone']);
- add_filter('woocommerce_enable_order_notes_field', '__return_false');
- add_filter('woocommerce_ship_to_different_address_checked', '__return_false');
- }
- return $fields;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement