【问题标题】:Add WP editor (WYSIWYG) to WooCommerce settings tab将 WP 编辑器 (WYSIWYG) 添加到 WooCommerce 设置选项卡
【发布时间】:2022-12-11 17:49:53
【问题描述】:

我在 WooCommerce 的自定义设置选项卡中创建了一个下拉管理字段,我想在下拉列表之外添加一个 WP 编辑器 (WYSIWYG)。

我怎样才能做到这一点?

这是我用来在 WC 设置选项卡中创建下拉列表的代码:

    public static function get_settings()
    {
        $product_categories_slug = ['value1', 'value2'];

        $settings = array(
            'section_title' => array(
                'name' => __('VIP settings', 'woocommerce-settings-tab-wc-vip'),
                'type' => 'title',
                'desc' => '',
                'id' => 'wc_settings_tab_wc_vip_section_title'
            ),
            'vip_cat_slug' => array(
                'name' => __('VIP category slug', 'woocommerce-settings-tab-wc-vip'),
                'type' => 'select',
                'options' => $product_categories_slug,
                'desc' => __('Select the category used for VIP', 'woocommerce-settings-tab-wc-vip'),
                'id' => 'vip_cat_slug'
            ),
            'section_end' => array(
                'type' => 'sectionend',
                'id' => 'wc_settings_tab_wc_vip_section_end'
            )
        );

        return apply_filters('wc_settings_tab_wc_vip_settings', $settings);
    }

谢谢你。

【问题讨论】:

    标签: wordpress woocommerce tabs settings wysiwyg


    【解决方案1】:

    WooCommerce 有一个用于自定义类型设置字段的操作挂钩,您可以使用它并使用它编写字段输出。

    这是钩子:

    do_action( 'woocommerce_admin_field_' . $value['type'], $value );
    

    你可以在includes/admin/class-wc-admin-settings.php 文件中找到这个钩子。

    因此,例如,如果您定义了'type' => 'wp_editor',那么您将像这样编写您的操作回调函数:

    function vh_woocommerce_admin_field_wp_editor_callback( $value ){
        // Write your table row with "wp_editor"
    }
    add_action( 'woocommerce_admin_field_wp_editor', 'vh_woocommerce_admin_field_wp_editor_callback' );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 2019-06-27
      • 2016-10-13
      • 1970-01-01
      相关资源
      最近更新 更多