WooCommerce 禁用自定义字段添加到他们的免费插件?

WooCommerce disabled custom field addition to their free plugin?

我无法通过 WooCommerce Hooks 创建自定义字段,如图所示

function woocommerce_product_custom_fields()
{
    global $woocommerce, $post;
    echo '<div class="product_custom_field">';
    woocommerce_wp_text_input(
        array(
            'id'          => '_custom_product_title',
            'placeholder' => 'Arabic Product Title',
            'label'       => __('Arabic Product Title', 'woocommerce'),
            'desc_tip'    => 'true'
        )
    );

    woocommerce_wp_textarea_input(
        array(
            'id'          => '_arabic_desc',
            'placeholder' => 'Arabic Description',
            'label'       => __('Arabic Description', 'woocommerce')
        )
    );
    echo '</div>';
}

// Display Fields
add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');

function woocommerce_product_custom_fields_save($post_id)
{
// Custom Product Text Field
$woocommerce_custom_product_text_field = $_POST['_custom_product_title'];
  if (!empty($woocommerce_custom_product_text_field))
     update_post_meta($post_id, '_custom_product_title', esc_attr($woocommerce_custom_product_text_field));
    
/*$woocommerce_custom_product_textarea = $_POST['_arabic_desc'];
  if (!empty($woocommerce_custom_product_textarea))
     update_post_meta($post_id, '_arabic_desc', esc_html($woocommerce_custom_product_textarea));*/
}
// Save Fields
//add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');

但是这些字段没有出现在管理面板 > 新产品或供应商 > 添加产品页面中。

我在 WooCommerce 权威 here also this thread

的 WP.org 中发现了两次提及

所以,他们只是删除了 free 方法中这些钩子的功能吗?那为什么不记录下来呢?

**

更新:我是看错地方看到代码运行ning了。正如回答者所报告的那样,它对他有用。我检查了更多以找出这可能生成的任何输出,并发现我折叠了一个选项卡,该选项卡最近因前一天的 WooCommerce 插件更新而更新。这几天当然有一些令人沮丧的时刻。部分原因是我最初在第二个 TextArea 名称中输入错误,但后来是由于折叠选项卡和 WCMarketPlace(WooCommerce 供应商的另一个插件)的另一个仪表板 运行 上的预期结果。

**

我刚刚检查了三天前更新后的最新 WooCommerce 文件,以验证挂钩和方法是否仍然相同,它们是。 woocommerce_product_options_general_product_data 仍在使用,以及 woocommerce_wp_text_input

然后我测试了你的代码,对我来说它有效。

您在保存文本区域的代码中确实有一些拼写错误。这是没有拼写错误的代码(我相信你写的是 procut 而不是 product)。

$woocommerce_custom_product_textarea = $_POST['_arabic_desc'];
  if (!empty($woocommerce_custom_product_textarea))
     update_post_meta($post_id, '_arabic_desc', esc_html($woocommerce_custom_product_textarea));