我试图将两个不同的部分添加到WooCommerce管理产品标签中。
以下代码仅在我不使用elseif()
时有效,如果添加此代码,则会出现以下错误:
Warning: Invalid argument supplied for foreach() in /wp-content/plugins/woocommerce/includes/admin/class-wc-admin-settings.php on line 197
代码:
// Create a section on the Products tab
add_filter('woocommerce_get_sections_products', 'myplugin_add_section');
function myplugin_add_section( $sections ) {
$sections['myplugin'] = __('My Plugin page', 'myplugin');
$sections['mypluginlog'] = __('My plugin Log', 'myplugin');
return $sections;
}
// Add Settings
add_filter('woocommerce_get_settings_products', 'myplugin_all_settings', 10, 2);
function myplugin_all_settings( $settings, $current_section ) {
if ($current_section == 'myplugin') {
// do something
}
elseif($current_section == 'mypluginlog') {
// do something else
}
else {
return $settings;
}