I am creating a plugin for Worpdress/WooCommerce. I have done all the stuff and now I want to add an option tab to woocommerce API settings, like in this instruction tutorial.
This is my code:
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;
}
}
But I am getting some errors:
Warning: Missing argument 2 for some_tab_settings() in C:OpenServerdomainswp-devwp-contentpluginssome-pluginsome_plugin.php on line 30
Notice: Undefined variable: current_section in C:OpenServerdomainswp-devwp-contentpluginssome-pluginsome_plugin.php on line 31
Related to:
add_filter( ‘woocommerce_get_settings_api’, ‘some_tab_settings’, 10, 2 ); ==> Line: 30
function some_tab_settings( $settings, $current_section ) { ==> Line: 31
How can I achieve this?
Looking first at the core source code of WC for WooCommerce API Settings and to this useful only tutorial (2016) I have found on the subject. Here is the code:
It’s used to create a new tab and a sub tab in woocommerce settings tab API. the second function displays HTML fields where you will be able to edit and save the settings.
Thanks to Daniel Halmagean
Update: Using the New Settings:
You would now just use your newly created settings like you would any other WordPress / WooCommerce setting, through the
get_option()
function and the defined ID of the setting (see reference below).For example if your settings
array
id is'custom_settings'
you will useget_option( 'custom_settings' )
. For more specific information on adding settings to WooCommerce, check out the wooThemes: Settings API. May be you can useecho var_dump();
function to see the outputted data:Reference:
wooThemes: Adding a Section to a Settings Tab
wooThemes: Settings API
Please try this with “woocommerce_get_settings_products” hook. You can not get current section from this( woocommerce_get_sections_api ) hook.