2017-05-18 8 views
6

배송 방법 페이지에서 맞춤 입력란을 추가하고 싶습니다. 입력란에 맞춤 입력란을 추가하면 맞춤 메시지를 추가 할 수 있습니다. 프런트 엔드에 그 메시지.배송 방법 (백엔드)에 맞춤 설명 입력란을 추가하는 방법

데이터를 저장하기위한 추가 열이없는 wp_woocommerce_shipping_zone_methods 테이블에 데이터를 저장하는 것으로 나타났습니다. 그래서 내 사용자 지정 논리를 사용해야한다고 생각하지만 hook (s)의 이름을 알지 못합니다.

그래서 제 질문은, 어떤 후크 도움이 될 것입니다이 이있다/내가

  1. 사용자 정의 필드를 추가 할 수 있습니다.
  2. 사용자 지정 열을 추가하려면.

TL; DR : enter image description here

시간에 늦은

enter image description here

+0

하면 데이터가 콧수염이 Underscore.js 템플릿을 영감을 사용하여 채워 동안 HTML의 믹스'th'와'tfoot'에 볼 수있는 테이블. 자세한 내용은'\ includes \ admin \ settings \ views \ html-admin-page-shipping-zone-methods.php'를보십시오. –

+0

배송 방법 설정의 모델은 또한 Underscore.js 템플릿을 기반으로합니다. 따라서 뷰를 수정하고 입력 된 데이터를 처리하려면 사용자 정의 JS를 사용해야합니다. 데이터 부분을 저장/검색하려면 코어 설정 API를 사용하여 옵션을 저장하면됩니다. 프론트 엔드에서 같은 것을 표시하려면 각 WC 템플리트에서 후크를 사용해야합니다. –

답변

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

$ 필드 배열이 최소한 있어야합니다

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

또한 다음을 지정할 수 있습니다

'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