我为我的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",
"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>';
}
&#13;
答案 0 :(得分:0)
我找到了解决方案:
"
&#13;