在 Woocommerce 的 WYSIWYG 编辑器字段中添加或替换变体字段 [英] Add or replace a variation fields into a WYSIWYG editor field in Woocommerce

查看:19
本文介绍了在 Woocommerce 的 WYSIWYG 编辑器字段中添加或替换变体字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何将 Woocommerce Variation Subscription 产品文本字段转换为 WYSIWYG 编辑器.

I'm trying to figure out how I can turn a Woocommerce Variation Subscription product text field into a WYSIWYG editor.

现在的样子:

如您所见,我将代码放入该字段以更新其外观,但这对我不知道代码的客户不起作用.如何向该字段添加文本编辑器?

As you can see I put code into that field to updates its appearance, but that isn't going to work for my client who knows no code. How can I add a text editor to this field?

推荐答案

变体描述无法替换,但可以隐藏(在需要时).

It's not possible to replace the variation description, but it can be hidden (in case of need).

可以向 Woocommerce 变体添加 WYSIWYG 编辑器.但它无法正常工作,因为在产品变体和订阅变体上启用了 jQuery 和 Ajax.

It's possible to add a WYSIWYG editor to Woocommerce variations. But it will not work properly due to jQuery and Ajax that is enabled on product variations and subscriptions variations.

代码如下:

// Add WYSIWYG custom field in Variation Settings
add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
function variation_settings_fields( $loop, $variation_data, $variation ) {

    $text_area = get_post_meta($variation->ID, '_description2', true) ? get_post_meta($variation->ID, '_description2', true) : '';
    $args['textarea_rows'] = 6;

    echo '<p>'.__( "Description 2", "woocommerce" ).'</p>';

    wp_editor( $text_area, "description2_$loop", $args );
}
// Save WYSIWYG custom field value as Variation post meta data
add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
function save_variation_settings_fields( $variation_id, $loop ) {
    if( isset( $_POST["description2_$loop"] ) )
        update_post_meta( $variation_id, '_description2', wp_kses_post( $_POST["description2_$loop"] ) );
}

代码位于活动子主题(或活动主题)的 function.php 文件中.

已测试但无法正常工作且存在问题:工具栏未出现且编辑器在文本"编辑器模式下被阻止,因此可视"编辑器模式(选项卡)不会出现不行.见下文:

Tested but doesn't work properly and it's bugged: The tool bar doesn't appear and the editor stays blocked on "text" editor mode, so "visual" editor mode (tab) doesn't work. See below:

它只是作为一个普通的文本区域字段,正确保存插补文本

It just works as a normal text area field, saving the imputed text correctly

这篇关于在 Woocommerce 的 WYSIWYG 编辑器字段中添加或替换变体字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆