حذف برخی فیلدها هنگام خرید محصولات دانلود شدنی

Mahmoodii

تازه وارد
با سلام و بسیار  از دوستانی که افزونه Persian Woocommerce Shipping رو نوشتن متشکرم.

مشکلی برام پیش اومده که امیدوارم راهش رو عزیزان بهم بگن :

من در فروشگاه هم محصولات دانلودی دارم و هم محصولات فیزیکی . وقتی کسی محصول دانلودی رو انتخاب می کنه با استفاده از کد زیر که تو فایل فانکشن گذاشتم ، فقط فیلد هایی که لازم هست رو میزارم و بقیه فیلد ها رو حذف می کنم. فیلد های مورد نیاز ( نام ، نام خانوادگی ، ایمیل و شماره موبایل هست ) اما از وقتی این افزونه رو نصب کردم توی این روند مشکل درست کرده و علاوه بر اون فیلدها ، فیلدهای دیگه رو هم نشون میده .

لطفا راهنمایی کنید چه کدهایی برای حذف اون فیلد ها باید در فایل فانکشن بزارم تا مشکل برطرف بشه .

کدی که تو فایل فانکشن گذاشتم این هست :

کد:
/**
 * Remove additional field for woocommerce digital goods in payment
 */

add_filter( 'woocommerce_checkout_fields' , 'woo_remove_billing_checkout_fields' );
/**
 * Remove unwanted checkout fields
 *
 * @return $fields array
*/
function woo_remove_billing_checkout_fields( $fields ) {
    
    if( woo_cart_has_virtual_product() == true ) {
	    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['order']['order_comments']);
	    unset($fields['billing']['billing_address_2']);
	    unset($fields['billing']['billing_postcode']);
	    unset($fields['billing']['billing_company']);
	    unset($fields['billing']['billing_city']);  
	    unset($fields['billing']['billing_myfield12']);
    }
    
    return $fields;
}
/**
 * Check if the cart contains virtual product
 *
 * @return bool
*/
function woo_cart_has_virtual_product() {
  
  global $woocommerce;
  
  // By default, no virtual product
  $has_virtual_products = false;
  
  // Default virtual products number
  $virtual_products = 0;
  
  // Get all products in cart
  $products = $woocommerce->cart->get_cart();
  
  // Loop through cart products
  foreach( $products as $product ) {
	  
	  // Get product ID and '_virtual' post meta
	  $product_id = $product['product_id'];
	  $is_virtual = get_post_meta( $product_id, '_virtual', true );
	  
	  // Update $has_virtual_product if product is virtual
	  if( $is_virtual == 'yes' )
  		$virtual_products += 1;
  }
  
  if( count($products) == $virtual_products )
  	$has_virtual_products = true;
  
  return $has_virtual_products;
}
 
بالا