【问题标题】:Add woocommerce checkout field to right column, not left将 woocommerce 结帐字段添加到右列,而不是左列
【发布时间】:2014-08-26 06:09:00
【问题描述】:

我正在将 woocommerce 与自定义主题集成。当我添加自定义结帐字段时,它显示在左列所有其他字段的底部。我希望它出现在右侧栏中,文本区域“订单备注”下方。

functions.php 中的代码:

// Change Checkout Fields
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
    // Add new fields to checkout
     $fields['billing']['card_requests'] = array(
        'type'      => 'textarea',
        'label'     => __('Card Requests', 'woocommerce'),
        'placeholder'   => _x('Please enter messages for your handwritten cards here.', 'placeholder', 'woocommerce'),
        'required'  => false
     );
    return $fields;
}

在输出的 HTML 中,有一个 col-1 div 和一个 col-2 div。我认为来自templates/formcheckout.php

        <div class="col-1">
            <?php do_action( 'woocommerce_checkout_billing' ); ?>
        </div>
        <div class="col-2">
            <?php do_action( 'woocommerce_checkout_shipping' ); ?>
        </div>

截图:

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    将以下内容添加到您的functions.php:

    // Change Checkout Fields
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    function custom_override_checkout_fields( $fields ) {
      // Add new fields below order notes section
      $fields['order']['card_requests'] = array(
        'type'      => 'textarea',
        'label'     => __('Card Requests', 'woocommerce'),
        'placeholder'   => _x('Please enter messages for your handwritten cards here.', 'placeholder', 'woocommerce'),
        'required'  => false
      );
      return $fields;
    }
    

    【讨论】:

    • 优秀。谢谢你。 (变化是 $fields['billing'] 到 $fields['order'])
    猜你喜欢
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    相关资源
    最近更新 更多