如何在Shipping方法(Backend)中添加Custom Description字段

Rau*_*pta 10 php wordpress shipping woocommerce hook-woocommerce

我想在送货方式下的Shipping Zone页面中添加一个自定义字段,它将是一个文本输入,用户将能够添加自定义消息,我将在前端显示该消息.

我注意到它将数据保存在wp_woocommerce_shipping_zone_methods表中,没有任何额外的列来保存数据; 所以我想我必须使用我的自定义逻辑,但我不知道hook的名称.

所以我的问题是,是否有任何钩子可以帮助/允许我

  1. 添加自定义字段.
  2. 添加自定义列.

TL; DR: 在此输入图像描述

在此输入图像描述

小智 -1

时间晚了,但你可以使用:

add_action('woocommerce_product_options_general_product_data', 'my_custom_fields');

function my_custom_fields() {
    $field = array(
       //This ID will be use on the _postmeta table as key_name
       'id' => 'my_custom_message',
       //Text that goes inside the label tag
       'label' => 'Message:',
       //This text will appear on the description column
       'description' => 'This is a custom message not part of WooCommerce',
       //Boolean that determines the display of the description
       'desc_tip' => true,
       //Standard html input placeholder
       'placeholder' => 'Type a message',
    );
    woocommerce_wp_text_input($field);
}

add_action('woocommerce_process_product_meta', 'save_my_custom_fields');

function save_my_custom_fields($post_id) {
    update_post_meta(
        $post_id,
        'my_custom_message',
        esc_attr($POST['my_custom_message'])
    );
}
Run Code Online (Sandbox Code Playgroud)

我认为 $field 数组必须至少具有:

$field = array(
    'id' => 'my_custom_message',//This ID will be use on the _postmeta table as key_name
    'label' => 'Message:',//Text that goes inside the label tag
    'description' => 'This is a custom message not part of WooCommerce',//This text will appear on the description column
    'desc_tip' => true,//Boolean that determines the display of the description
    'placeholder' => 'Type a message',//Standard html input placeholder
);
Run Code Online (Sandbox Code Playgroud)

您还可以指定以下内容:

    'class' => 'css-class',//Class attributte for the input tag
    'style' => 'background:red',//Style attribute for the input tag
    'wrapper_class' => 'css-class',//Class for the wrapper of the input tag, it is a paragraph
Run Code Online (Sandbox Code Playgroud)

  • 他正在尝试在设置->运输区域->运输方法中向运输方式添加字段。不是在产品本身上。 (4认同)