WooCommerce已将自定义字段添加到其免费插件中吗?

问题描述

我无法通过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机构herethis thread的WP.org中发现了两次提及

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

**

更新:我在错误的位置查看代码的运行。正如asnwerer报告的那样,它为他工作。我检查了更多内容以查找可能产生的任何输出,并发现我折叠了一个选项卡,该选项卡由于前一天的WooCommerce插件更新而被最近更新。当然,这是几天令人沮丧的时刻。最初部分是我在第二TextArea名称上输入的拼写错误,但后来是由于标签折叠并在WcmarketPlace运行的另一个仪表板(来自WooCommerce的供应商的另一个附加组件)上期望结果。

**

解决方法

我只是检查了三天前更新以来最新的WooCommerce文件,以验证挂钩和方法是否相同。 woocommerce_wp_text_input$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)); 仍在使用。

然后我测试了您的代码,对我来说它可以正常工作。

enter image description here

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

window['recaptchaVerifier'].clear()