4

Worpdress/WooCommerce 용 플러그인을 만들고 있습니다. 모든 작업을 완료했으며 이제는 instruction tutorial과 같은 woocommerce API 설정에 옵션 탭을 추가하려고합니다. WooCommerce 용 플러그인 만들기 : API 설정에 옵션 탭 추가

내 코드입니다 :

add_filter('woocommerce_get_sections_api', 'some_function_to_add_tab'); 

function some_function_to_add_tab($sections) { 
    $sections['some_settings'] = __('Some Settings', 'text-domain'); 
    return $sections; 
} 

add_filter('woocommerce_get_settings_api', 'some_tab_settings', 10, 2); 

function some_tab_settings($settings, $current_section) { 
    if ($current_section == 'some_settings') { 
     echo "settings here"; 
    } else { 
     return $settings; 
    } 
} 

하지만 약간의 오차가 점점 오전 :

경고 : C에서 some_tab_settings()에 대한 인수 2를 누락 : \ 오픈 서버 \ 도메인 \ WP-DEV \ wp-content \ plugins \ some-plugin \ some_plugin.php on line 30

Notice : C : \ OpenServer \ domains \ wp-dev \ wp-content \ plugins \ some-plugin \ some_plugin에서 정의되지 않은 변수 : current_section. php on line 31

,

관련에 :

add_filter ('woocommerce_get_settings_api', 'some_tab_settings', 10, 2); ==>라인 : 30

기능 some_tab_settings ($ 설정, $의 current_section) {==>라인 : 31

가 어떻게 이것을 달성 할 수 있습니까?

+0

@LoicTheAzte 당신이 출력 된 데이터를 볼 수 echo var_dump(); 기능을 사용할 수 있습니다 수 있음 나는 또 하나의 질문을 가지고있다. 어떻게 데이터를 데이 터베이스에 삽입하기 위해 튜토리얼에서 양식을 사용할 수 있는가? "입력"버튼을 클릭하고 입력 데이터에 내 글을 쓰고 싶습니다. 이제 삽입하는 방법, array()로 만든 양식을 사용하는 방법이 아님 – pwnz22

답변

2

WC for WooCommerce API Settings의 핵심 소스 코드를 먼저 찾고 및 this useful only tutorial (2016)에 나는 주제에 발견했다. 코드는 다음과 같습니다.

// creating a new sub tab in API settings 
add_filter('woocommerce_get_sections_api','add_subtab'); 
function add_subtab($settings_tabs) { 
    $settings_tabs['custom_settings'] = __('Custom Settings', 'woocommerce-custom-settings-tab'); 
    return $settings_tabs; 
} 


// adding settings (HTML Form) 
add_filter('woocommerce_get_settings_api', 'add_subtab_settings', 10, 2); 
function add_subtab_settings($settings) { 
    $current_section = (isset($_GET['section']) && !empty($_GET['section']))? $_GET['section']:''; 
    if ($current_section == 'custom_settings') { 
     $custom_settings = array(); 
     $custom_settings[] = array('name' => __('Custom Settings', 'text-domain'), 
            'type' => 'title', 
            'desc' => __('The following options are used to ...', 'text-domain'), 
            'id' => 'custom_settings' 
           ); 

     $custom_settings[] = array(
            'name'  => __('Field 1', 'text-domain'), 
            'id'  => 'field_one', 
            'type'  => 'text', 
            'default' => get_option('field_one'), 

           ); 

     $custom_settings[] = array('type' => 'sectionend', 'id' => 'test-options');    
     return $custom_settings; 
    } else { 
     // If not, return the standard settings 
     return $settings; 
    } 
} 

woocommerce 설정 탭 API에 새 탭과 하위 탭을 만드는 데 사용됩니다. 두 번째 기능은 설정을 편집하고 저장할 수있는 HTML 필드를 표시합니다. 새 설정을 사용 :

감사 Daniel Halmagean


업데이트에

당신 것 이제 당신처럼 새로 만든 설정을 사용하는 것과 get_option() 기능을 통해 다른 워드 프레스/WooCommerce 설정, 및 설정의 정의 된 ID (아래 참조).

예를 들어 array ID가 'custom_settings' 인 경우 get_option('custom_settings')을 사용합니다. WooCommerce에 설정을 추가하는 방법에 대한 자세한 내용은 wooThemes: Settings API을 확인하십시오.

$my_data = get_option('custom_settings'); 
echo var_dump($my_data); 

참조 :

+0

Didnt는이 양식을 사용하는 방법을 정말로 이해하지 못했습니다 :(그러나 저는 documentaion을 계속 읽습니다 :) 고맙습니다. – pwnz22

0

"woocommerce_get_settings_products"후크로 시도하십시오. 이 섹션에서 현재 섹션을 가져올 수 없습니다 (woocommerce_get_sections_api).

add_filter('woocommerce_get_settings_products', 'some_tab_settings', 10, 2); 

function some_tab_settings($settings, $current_section) { 
    if ($current_section == 'some_settings') { 
     echo "settings here"; 
    } else { 
     return $settings; 
    } 
} 
+0

하지만 여기에 내 설정을 넣으 려합니다. http://i.stack.imgur.com/bsjkc.png – pwnz22

+0

이 후크를 추가하십시오 add_filter ('woocommerce_get_sections_products', 'some_function_to_add_tab'); function some_function_to_add_tab ($ sections) { $ 섹션 [ 'some_settings'] = __ ('일부 설정', '텍스트 도메인'); return $ sections; } –

+0

이 필터는 제품 탭에 옵션을 추가합니다. 하지만 API 섹션에 설정 탭이 필요합니다. – pwnz22

관련 문제