Advertisement
verygoodplugins

Untitled

Oct 30th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. add_filter( 'woocommerce_checkout_fields' , 'bbloomer_simplify_checkout_virtual' );
  2.  
  3. function bbloomer_simplify_checkout_virtual( $fields ) {
  4.  
  5.     if( is_admin() ) {
  6.         return $fields;
  7.     }
  8.      
  9.     $only_virtual = true;
  10.      
  11.     foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  12.         // Check if there are non-virtual products
  13.         if ( ! $cart_item['data']->is_virtual() ) $only_virtual = false;
  14.     }
  15.      
  16.     if( $only_virtual ) {
  17.         unset($fields['billing']['billing_company']);
  18.         unset($fields['billing']['billing_address_1']);
  19.         unset($fields['billing']['billing_address_2']);
  20.         unset($fields['billing']['billing_city']);
  21.         unset($fields['billing']['billing_postcode']);
  22.         unset($fields['billing']['billing_country']);
  23.         unset($fields['billing']['billing_state']);
  24.         unset($fields['billing']['billing_phone']);
  25.         add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
  26.     }
  27.      
  28.     return $fields;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement