Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为WooCommerce创建插件:向API设置添加选项选项卡_Php_Wordpress_Woocommerce_Hook Woocommerce_Wordpress Hook - Fatal编程技术网

Php 为WooCommerce创建插件:向API设置添加选项选项卡

Php 为WooCommerce创建插件:向API设置添加选项选项卡,php,wordpress,woocommerce,hook-woocommerce,wordpress-hook,Php,Wordpress,Woocommerce,Hook Woocommerce,Wordpress Hook,我正在为WorpAddress/WooCommerce创建一个插件。我已经完成了所有的工作,现在我想在WooCommerceAPI设置中添加一个选项选项卡,如下所示 这是我的代码: add_filter( 'woocommerce_get_sections_api', 'some_function_to_add_tab' ); function some_function_to_add_tab( $sections ) { $sections['some_settings'] = __

我正在为WorpAddress/WooCommerce创建一个插件。我已经完成了所有的工作,现在我想在WooCommerceAPI设置中添加一个选项选项卡,如下所示

这是我的代码:

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;
    }
}
但我得到了一些错误:

警告:第30行C:\OpenServer\domains\wp dev\wp content\plugins\some plugin\some\u plugin.php中的某些\u选项卡\u设置()缺少参数2

注意:未定义变量:第31行C:\OpenServer\domains\wp dev\wp content\plugins\some plugin\some\u plugin.php中的当前\u部分

有关:

添加过滤器('woocommerce\u get\u settings\u api','some\u tab\u settings',10,2);=>行:30

函数一些选项卡设置($settings,$current\u section){=>行:31

如何实现此目的?

请使用“woocommerce\u get\u settings\u products”钩子尝试此操作。您无法从此(woocommerce\u get\u sections\u api)钩子获取当前节


首先查看我在该主题上找到的和(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字段,您可以在其中编辑和保存设置

多亏了


更新:使用新设置:

现在,您可以像使用任何其他WordPress/WooCommerce设置一样,通过
get\u option()
函数和定义的设置ID来使用新创建的设置(参见下面的参考资料)

例如,如果您的设置
array
id是
'custom\u settings'
您将使用
get\u选项('custom\u settings')
。有关向WooCommerce添加设置的更多具体信息,请查看。可能您可以使用
echo var\u dump();
函数查看输出的数据:

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

参考:


请添加此钩子添加过滤器('woocommerce\u get\u sections\u products'、'some\u function\u to\u add\u tab');function some\u function\u to\u add\u tab($sections){$sections['some\u settings']=\uuu('some settings',text domain');return$sections;}此筛选器正在向“产品”选项卡添加选项。但我需要API部分中的“设置”选项卡。很抱歉出错。请在没有当前部分的情况下使用此筛选器。woocommerce默认情况下管理此当前部分。添加\u筛选器('woocommerce\u get\u settings\u API','some\u tab\u settings',10,2);使用某些\u选项卡设置($settings){echo“settings here”;return$settings;}
function-syncretailcrm_-settings($settings){if($\u-GET['section']='some_-settings'){adminMenu();}else{return$settings;}}
我做了以下操作,现在转到设置选项卡时出现此错误:
警告:为foreach()提供的参数无效在C:\OpenServer\domains\wp dev\wp content\plugins\woocommerce\includes\admin\class-wc-admin-settings.php中,第222行
您想用什么来使用syncretailcrm\u设置此函数。@LoicTheAztec我还有一个问题:)您能解释一下如何使用教程中的表单将数据插入数据库吗?就像我在输入中写了什么一样“保存”按钮和数据插入到我的表中。我现在知道如何插入,但不知道如何使用数组()创建的表单。我真的不知道如何使用此表单:(.但我将继续阅读文档:)thanx
$my_data = get_option( 'custom_settings' );
echo var_dump( $my_data );