Advertisement
Socialking

Untitled

Apr 25th, 2022
1,120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. add_filter('woocommerce_checkout_fields', 'conditionally_remove_checkout_fields', 25, 1);
  2. function conditionally_remove_checkout_fields($fields)
  3. {
  4.  
  5.       $categories = array('house');
  6.       $found = false;
  7.  
  8.       foreach (WC()->cart->get_cart() as $cart_item) {
  9.             if (has_term($categories, 'product_cat', $cart_item['product_id'])) {
  10.                   $found = true;
  11.                   break;
  12.             }
  13.       }
  14.  
  15.       if ($found) {
  16.             unset($fields['shipping']['shipping_first_name']);
  17.             unset($fields['shipping']['shipping_last_name']);
  18.             unset($fields['shipping']['shipping_company']);
  19.             unset($fields['shipping']['shipping_address_1']);
  20.             unset($fields['shipping']['shipping_address_2']);
  21.             unset($fields['shipping']['shipping_city']);
  22.             unset($fields['shipping']['shipping_postcode']);
  23.             unset($fields['shipping']['shipping_country']);
  24.             unset($fields['shipping']['shipping_state']);
  25.             unset($fields['shipping']['shipping_phone']);
  26.  
  27.             add_filter('woocommerce_enable_order_notes_field', '__return_false');
  28.             add_filter('woocommerce_ship_to_different_address_checked', '__return_false');
  29.       }
  30.       return $fields;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement