繁体   English   中英

在 WooCommerce 3 中“创建帐户”上方移动结帐订单备注字段

[英]Move Checkout Order notes field above "create an account" in WooCommerce 3

我使用的是 WooCommerce 3.2.1 版,我尝试在我的主题functions.php添加以下代码以移动订单备注结帐字段,但它不起作用:

add_filter( 'woocommerce_checkout_fields', 'bbloomer_move_checkout_fields_woo_3');
  function bbloomer_move_checkout_fields_woo_3( $fields ) {
  $fields['order']['order_comments']['priority'] = 8;
  return $fields;
}

我想将订单备注 textarea 字段移到“create_account”复选框上方和结帐页面上的“billing_postcode”字段下方。

我怎样才能让它工作?

在下面的代码中:

  • 我删除了“订单备注”
  • 我添加了一个类似的自定义帐单字段(名为“billing_customer_note”)
  • 我对字段重新排序 (*)
  • 在结帐时提交订单后,我将自定义帐单字段“客户备注”数据添加为经典订单备注……

这是代码:

// Checkout fields customizations
add_filter( 'woocommerce_checkout_fields' , 'customizing_checkout_fields', 10, 1 );
function customizing_checkout_fields( $fields ) {
    // Remove the Order Notes
    unset($fields['order']['order_comments']);

    // Define custom Order Notes field data array
    $customer_note  = array(
        'type' => 'textarea',
        'class' => array('form-row-wide', 'notes'),
        'label' => __('Order Notes', 'woocommerce'),
        'placeholder' => _x('Notes about your order, e.g. special notes for delivery.', 'placeholder', 'woocommerce')
    );

    // Set custom Order Notes field
    $fields['billing']['billing_customer_note'] = $customer_note;

    // Define billing fields new order
    $ordered_keys = array(
        'billing_first_name',
        'billing_last_name',
        'billing_company',
        'billing_country',
        'billing_address_1',
        'billing_address_2',
        'billing_city',
        'billing_state',
        'billing_postcode',
        'billing_phone',
        'billing_email',
        'billing_customer_note', // <= HERE
    );

    // Set billing fields new order
    $count = 0;
    foreach( $ordered_keys as $key ) {
        $count += 10;
        $fields['billing'][$key]['priority'] = $count;
    }

    return $fields;
}

// Set the custom field 'billing_customer_note' in the order object as a default order note (before it's saved)
add_action( 'woocommerce_checkout_create_order', 'customizing_checkout_create_order', 10, 2 );
function customizing_checkout_create_order( $order, $data ) {
    $order->set_customer_note( isset( $data['billing_customer_note'] ) ? $data['billing_customer_note'] : '' );
}

代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中。

测试和工作。

暂无
暂无

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

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