2017-05-18 13 views
6

Chcę dodać niestandardowe pole na stronie Strefy wysyłki w ramach metody wysyłki, będzie to wprowadzenie tekstowe, użytkownik będzie mógł dodać niestandardową wiadomość, a ja pokażę tę wiadomość z przodu.Jak dodać pole niestandardowego opisu w metodach wysyłki (Backend)

Zauważyłem, że zapisuje dane w tabeli wp_woocommerce_shipping_zone_methods, które nie mają żadnej dodatkowej kolumny do zapisania danych; więc myślę, że muszę użyć mojej niestandardowej logiki, ale nie znam nazwy haka (-ów).

Więc moje pytanie brzmi, czy istnieje każdy hak które pomogą/pozwoli mi

  1. Aby dodać pole niestandardowe.
  2. Aby dodać niestandardową kolumnę.

TL; DR: enter image description here

enter image description here

+0

stół, który widzisz jest mieszanką HTML w '' tfoot' th' i gdy dane są wypełniane przy użyciu szablonów underscore.js Wąsy inspirowane. Możesz zajrzeć do '\ includes \ admin \ settings \ views \ html-admin-page-shipping-zone-methods.php', by dowiedzieć się więcej. –

+0

Model ustawień metody dostawy jest również oparty na szablonie Underscore.js. Aby zmodyfikować widok i przetwarzanie wprowadzonych danych, należy użyć niestandardowego JS. Do przechowywania/pobierania części danych można to zrobić za pomocą interfejsu podstawowego api i zapisać je w opcjach. Aby wyświetlać to samo na interfejsie musisz użyć haczyków w każdym szablonie WC. –

Odpowiedz

0

Późno w czasie, ale można użyć:

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

$ array pole moim zdaniem musi mieć co najmniej:

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

Można również określić:

'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 
Powiązane problemy