将多个部分添加到WooCommerce选项卡

时间:2018-09-10 17:58:24

标签: php wordpress woocommerce

我试图将两个不同的部分添加到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;
        }

0 个答案:

没有答案