如何在WooCommerce->送货方式中添加额外的自定义字段

时间:2019-11-06 10:25:08

标签: wordpress woocommerce

我想在其中添加额外的自定义字段 WordPress-> WooCommerce->设置->发货方式

步骤:1

enter image description here

赞:

enter image description here

步骤:2(输出)

enter image description here

1 个答案:

答案 0 :(得分:0)

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'])
    );
}

请尝试使用上面的代码,并将id字段替换为所需的参数