0
我做了一個自定義的設計,我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>';
}