简体   繁体   English

结帐字段在Woocommerce购物车页面中具有2列

[英]Checkout fields to have 2 columns in Woocommerce cart page

I have found the solution to have the following fields in-line with each other on the woocommerce checkout page - orignal question here: Customizing checkout fields on 2 columns in Woocommerce cart page 我发现该解决方案在woocommerce结帐页面上使以下字段彼此一致-这里的原始问题: 在Woocommerce购物车页面的2列上自定义结帐字段

Most fields with this code become inline, however the following fields have no affect: 使用此代码的大多数字段都变为内联,但是以下字段无效:

  • Phone 电话
  • Email 电子邮件
  • Address line 2 地址行2

I think it's an error within the billing section in the code. 我认为这是代码的结算部分中的错误。 This is the full code: 这是完整的代码:

add_filter( 'woocommerce_checkout_fields' , 'custom_checkout_billing_fields', 20, 1 );
function custom_checkout_billing_fields( $fields ){

if( is_cart()){ // <== On cart page only
    // Change placeholder
    $fields['billing_phone']['placeholder']     = __( 'Phone', $domain );
    $fields['billing_email']['placeholder']     = __( 'Email', $domain );
    $fields['billing_address_2']['placeholder'] = __( 'Address line 2', $domain );

    // Change class
    $fields['billing_phone']['class']     = array('form-row-last'); //  50%
    $fields['billing_email']['class']     = array('form-row-first');  //  50%
    $fields['billing_address_2']['class'] = array('form-row-wide');  // 100%
}
return $fields;
}

add_filter('woocommerce_default_address_fields', 'custom_default_address_fields', 20, 1);
function custom_default_address_fields( $address_fields ){

if( ! is_cart()){ // <== On cart page only
    // Change placeholder
    $address_fields['first_name']['placeholder'] = __( 'First name', $domain );
    $address_fields['last_name']['placeholder']  = __( 'Last name', $domain );
    $address_fields['address_1']['placeholder']  = __( 'Address line 1', $domain );
    $address_fields['state']['placeholder']      = __( 'County', $domain );
    $address_fields['postcode']['placeholder']   = __( 'Post Code', $domain );
    $address_fields['city']['placeholder']       = __( 'Town/City', $domain );

    // Change class
    $address_fields['first_name']['class'] = array('form-row-first'); //  50%
    $address_fields['last_name']['class']  = array('form-row-last');  //  50%
    $address_fields['address_1']['class']  = array('form-row-wide');  // 100%
    $address_fields['state']['class']      = array('form-row-last');  // 50%
    $address_fields['postcode']['class']   = array('form-row-first'); //  50%
    $address_fields['city']['class']       = array('form-row-first');  //  50%
}
return $address_fields;
}

Here is the css code: 这是CSS代码:

.form-row-wide,
.form-row-first,
.form-row-last {
    clear: both !important;
    float: none !important;
    width: 100% !important;
    margin-right: 0 !important;
}

@media (min-width: 768px){
    .form-row-first {
       width: 47% !important;
       float: left !important;
       margin-right: 5.8% !important;
       clear: both !important;
    }
    .form-row-last {
       width: 47% !important;
       float: right !important;
       margin-right: 0 !important;
       clear: none !important;
    }
}

you have some mistake in your code and i believe the answer which you took those code from is for similar solution and not for your case. 您的代码中有一些错误,我相信您从这些代码中获取的答案是针对类似的解决方案,而不是针对您的情况。

So if you want to display the checkout filed inline you need only the following: 因此,如果要显示内联的结帐字段,则仅需要以下内容:

 add_filter('woocommerce_checkout_fields', 'custom_checkout_billing_fields', 20, 1);
 function custom_checkout_billing_fields($fields)
 {
$domain = 'woocommerce';
// Remove billing address 2
unset($fields['billing']['billing_address_2']);

// Change class
$fields['billing']['billing_phone']['class'] = array('form-row-first'); //  50%
$fields['billing']['billing_email']['class'] = array('form-row-last'); //  50%
$fields['billing']['billing_address_1']['class'] = array('form-row-first'); //  50%
$fields['billing']['billing_postcode']['class'] = array('form-row-last'); //  50%
$fields['billing']['billing_company']['class'] = array('form-row-wide'); // 100%

// Change placeholder this below is just if you wanto to change the place holder  you can remove theme if you don't want to change that
$fields['billing']['billing_phone']['placeholder'] = __('Telefon', $domain);
$fields['billing']['billing_email']['placeholder'] = __('Email', $domain);
$fields['billing']['billing_company']['placeholder'] = __('Firmanavn', $domain);

return $fields;
}

in above code only five filed which we have change the classes if you want the rest let me know or you can add them by yourself by looking for each filed name and change the class in the way you want 在上面的代码中,只有五个归档了,如果您想让其他人知道,我们可以更改类,也可以通过查找每个归档的名称来自己添加它们,并以所需的方式更改类

Remember there is block of code in this function that change the placeholder if you don't want them you can simple delete them 请记住,此函数中有一些代码块可以更改占位符,如果您不希望它们可以简单地删除它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM