WooCommerce必填字段错误

问题描述:

我做了一个自定义的设计,我WooCommerce结帐时间最长的,它的工作就好了,但是好像最近我不能再结账。即使我填写了所有的字段,我也会得到一个错误,说我必须填写某些字段。这是我使用的代码,我期待要么修复它,使它只需要我在这个代码或最坏的情况只写一个代码,以便它从来没有要求任何东西要填写的字段。WooCommerce必填字段错误

我做了一些进一步的测试,我只使用计费领域,但错误出现航运领域。我需要运输和结算领域同一个或只是不再有出货需要作为计费字段的字段似乎很好地工作。

function custom_override_checkout_fields($fields) { 
 
    unset($fields['billing']['billing_company']); 
 
    unset($fields['billing']['billing_country']); 
 
    unset($fields['billing']['billing_address_2']); 
 

 
    return $fields; 
 
} 
 

 
add_filter('woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100); 
 

 
add_filter('woocommerce_checkout_fields' , 'custom_override_checkout_fields'); 
 

 

 
// for billing fields 
 

 
    add_filter("woocommerce_checkout_fields", "new_order_fields"); 
 

 
     function new_order_fields($fields) { 
 

 
      $order = array(   
 
       "billing_first_name", 
 
       "billing_last_name", 
 
       "billing_address_1", 
 
       "billing_city", 
 
       "billing_postcode", 
 
       "billing_phone", 
 
\t \t   "billing_email" 
 

 
      ); 
 
      foreach($order as $field) 
 
      { 
 
       $ordered_fields[$field] = $fields["billing"][$field]; 
 
      } 
 

 
      $fields["billing"] = $ordered_fields; 
 
      return $fields; 
 

 
     } 
 

 
      // for shipping fields 
 
     add_filter("woocommerce_checkout_fields", "new_shiping_order_fields"); 
 

 
     function new_shiping_order_fields($fields) { 
 

 
      $order = array( 
 
       "shipping_city", 
 
       "shipping_postcode", 
 
       "shipping_country", 
 
       "shipping_first_name", 
 
       "shipping_last_name", 
 
       "shipping_company", 
 
       "shipping_address_1", 
 
       "shipping_address_2" 
 

 
      ); 
 
      foreach($order as $field) 
 
      { 
 
       $ordered_fields[$field] = $fields["shipping"][$field]; 
 
      } 
 

 
      $fields["shipping"] = $ordered_fields; 
 
      return $fields; 
 

 
     } 
 
// WooCommerce Checkout Fields Hook 
 
add_filter('woocommerce_checkout_fields' , 'custom_wc_checkout_fields'); 
 
    
 
// Change order comments placeholder and label, and set billing phone number to not required. 
 
function custom_wc_checkout_fields($fields) { 
 
$fields['billing']['billing_first_name']['placeholder'] = 'Fornavn'; 
 
$fields['billing']['billing_first_name']['label'] = false; 
 
$fields['billing']['billing_last_name']['placeholder'] = 'Efternavn'; 
 
$fields['billing']['billing_last_name']['label'] = false; 
 
$fields['billing']['billing_address_1']['placeholder'] = 'Adresse'; 
 
$fields['billing']['billing_address_1']['label'] = false; 
 
$fields['billing']['billing_postcode']['placeholder'] = 'Postnummer'; 
 
$fields['billing']['billing_postcode']['label'] = false; 
 
$fields['billing']['billing_city']['placeholder'] = 'By'; 
 
$fields['billing']['billing_city']['label'] = false; 
 
$fields['billing']['billing_phone']['placeholder'] = 'Telefon'; 
 
$fields['billing']['billing_phone']['label'] = false; 
 
$fields['billing']['billing_email']['placeholder'] = 'E-mail'; 
 
$fields['billing']['billing_email']['label'] = false; 
 

 
return $fields; 
 
} 
 
function ra_change_translate_text_multiple($translated) { 
 
    $text = array(
 
     'Send til en anden adresse?' => 'Tryk her for at vælge en alternativ leveringsadresse', 
 
     'Billing details' => '1. Kundeinformationer', 
 
     'Din ordre' => 'Deres bestilling', 
 
     'Opret en konto?' => 'Gem mine informationer til næste køb', 
 
     'Afgiv ordre' => 'Gå til sikker betaling', 
 
     'Bemærkninger om Deres bestilling, f.eks. særlige bemærkninger for levering.' => 'Indtast kommentar til ordre eller specielle ønsker her.' 
 
    ); 
 
    $translated = str_ireplace( array_keys($text), $text, $translated); 
 
    return $translated; 
 
} 
 
add_filter('gettext', 'ra_change_translate_text_multiple', 20); 
 
/** 
 
* Add the field to the checkout page 
 
*/ 
 
add_action('billing_email', 'customise_checkout_field'); 
 

 
function customise_checkout_field($checkout) 
 
{ 
 
    echo '<div id="customise_checkout_field"><h2>' . __('Heading') . '</h2>'; 
 
    woocommerce_form_field('customised_field_name', array(
 
     'type' => 'text', 
 
     'class' => array(
 
     'my-field-class form-row-wide' 
 
     ) , 
 
     'label' => __('Customise Additional Field') , 
 
     'placeholder' => __('Guidence') , 
 
     'required' => true, 
 
    ) , $checkout->get_value('customised_field_name')); 
 
    echo '</div>'; 
 
}

我找到了一个解决方案:

//make shipping fields not required in checkout 
 
add_filter('woocommerce_shipping_fields', 'wc_npr_filter_shipping_fields', 10, 1); 
 
function wc_npr_filter_shipping_fields($address_fields) { 
 
\t $address_fields['shipping_first_name']['required'] = false; 
 
\t $address_fields['shipping_last_name']['required'] = false; 
 
\t $address_fields['shipping_address_1']['required'] = false; 
 
\t $address_fields['shipping_city']['required'] = false; 
 
\t $address_fields['shipping_postcode']['required'] = false; 
 
\t \t return $address_fields; 
 
}