WooCommerce“保存更改”按钮出现在自定义设置中

时间:2014-01-03 作者:Eugene Manuilov

我正在编写WooCommerce插件,它需要自定义设置页面。我决定通过添加新的自定义选项卡来扩展常规WooCommerce设置。我已经设法用WooCommerce的方式做到了这一点,一切看起来都很好。但是,当我尝试渲染设置时Save Changes 按钮渲染不正确。

下面是它的样子:

enter image description here

下面是测试插件:

<?php
/**
 * Plugin Name: WooCommerce Settings Bug
 */

add_action( \'woocommerce_settings_start\', \'wpse8170_register_settings\' );
function wpse8170_register_settings() {
    global $woocommerce_settings;

    $woocommerce_settings[\'test\'] = array(
        array( \'type\' => \'title\', \'title\' => __( \'My Test Options\', \'wc-loyal-customer\' ), \'desc\' => \'\', \'id\' => \'test-options\' ),

        array(
            \'title\'    => __( \'Enable Test\', \'some-text-domain\' ),
            \'desc\'     => __( \'Enable test options\', \'some-text-domain\' ),
            \'id\'       => \'test_option\',
            \'type\'     => \'checkbox\',
            \'default\'  => \'yes\',
        ),
    );
}

add_filter( \'woocommerce_settings_tabs_array\', \'wpse8170_register_settings_tab\', PHP_INT_MAX );
function wpse8170_register_settings_tab( $tabs ) {
    $tabs[\'test\'] = esc_html__( \'Test tab\', \'some-text-domain\' );
    return $tabs;
}

add_action( \'woocommerce_settings_tabs_test\', \'wpse8170_render_settings_page\' );
function wpse8170_render_settings_page() {
    global $woocommerce_settings, $current_tab;
    woocommerce_admin_fields( $woocommerce_settings[$current_tab] );
}
这是一个非常简单的示例,但工作不正常。。。我做错了什么?

1 个回复
最合适的回答,由SO网友:Eugene Manuilov 整理而成

好的,修复很容易,虽然一点也不明显。我们只需添加array( \'type\' => \'sectionend\', \'id\' => \'test-options\' ), “设置”组的末尾。因此,最终函数应如下所示:

add_action( \'woocommerce_settings_start\', \'wpse8170_register_settings\' );
function wpse8170_register_settings() {
    global $woocommerce_settings;

    $woocommerce_settings[\'test\'] = array(
        array( \'type\' => \'title\', \'title\' => __( \'My Test Options\', \'wc-loyal-customer\' ), \'desc\' => \'\', \'id\' => \'test-options\' ),

        array(
            \'title\'    => __( \'Enable Test\', \'some-text-domain\' ),
            \'desc\'     => __( \'Enable test options\', \'some-text-domain\' ),
            \'id\'       => \'test_option\',
            \'type\'     => \'checkbox\',
            \'default\'  => \'yes\',
        ),

        array( \'type\' => \'sectionend\', \'id\' => \'test-options\' ),
    );
}

结束

相关推荐

使用主题文件夹代替plugins_url

我想这很简单,但我无法解决。我正在尝试通过我的主题向WordPress仪表板添加菜单页。我有以下。。。add_menu_page( \'Test\', \'Test\', \'manage_options\', \'myplugin/myplugin-admin.php\', \'\', plugins_url( \'myplugin/image/icon.png\' ), 6 &