2017-05-18 15 views
6

Tôi muốn thêm trường tùy chỉnh trong trang Vùng vận chuyển theo phương thức giao hàng, đó sẽ là kiểu nhập văn bản, người dùng có thể thêm thông báo tùy chỉnh và tôi sẽ hiển thị tin nhắn đó ở giao diện người dùng.Cách thêm trường Mô tả tùy chỉnh vào Phương thức giao hàng (Phụ trợ)

Tôi nhận thấy nó lưu dữ liệu trong wp_woocommerce_shipping_zone_methods bảng không có bất kỳ cột bổ sung nào để lưu dữ liệu; vì vậy tôi nghĩ rằng tôi phải sử dụng logic tùy chỉnh của mình, nhưng tôi không biết tên của hook (s).

Vì vậy, câu hỏi của tôi là, là có bất kỳ móc mà sẽ giúp/cho phép tôi

  1. Để thêm một lĩnh vực tùy chỉnh.
  2. Để thêm cột tùy chỉnh.

TL; DR: enter image description here

enter image description here

+0

Bảng mà bạn thấy là kết hợp HTML trong 'th' và' tfoot' trong khi dữ liệu được điền bằng cách sử dụng mẫu lấy cảm hứng từ Mustache mẫu Underscore.js. Bạn có thể xem '\ include \ admin \ settings \ lượt xem \ html-admin-page-shipping-zone-methods.php' để biết thêm chi tiết. –

+0

Mô hình cho cài đặt Phương thức giao hàng cũng dựa trên mẫu Underscore.js. Vì vậy, để sửa đổi chế độ xem và xử lý dữ liệu đã nhập, bạn phải sử dụng JS tùy chỉnh. Để lưu trữ/lấy phần dữ liệu, bạn có thể làm như vậy bằng cách sử dụng cài đặt lõi api và lưu chúng trong các tùy chọn. Để hiển thị tương tự trên giao diện người dùng, bạn phải sử dụng các móc trong mỗi mẫu WC. –

Trả lời

0

Cuối năm thời gian, nhưng bạn có thể sử dụng:

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

$ lĩnh vực mảng trong quan điểm của tôi phải có tối thiểu:

$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 
); 

Bạn cũng có thể chỉ định các nội dung sau:

'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 
Các vấn đề liên quan