【问题标题】:How to add extra custom field into WooCommerce -> Shipping Method如何将额外的自定义字段添加到 WooCommerce -> 运输方式
【发布时间】:2019-11-06 10:25:08
【问题描述】:

我想添加额外的自定义字段到 WordPress -> WooCommerce -> 设置 -> 运输方式

步骤:1

像这样:

步骤:2(输出)

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:
    add_action('woocommerce_product_options_general_product_data', 'my_custom_fields');
    
    function my_custom_fields() {
        $field = array(
           //This ID will be use on the _postmeta table as key_name
           'id' => 'my_custom_message',
           //Text that goes inside the label tag
           'label' => 'Message:',
           //This text will appear on the description column
           'description' => 'This is a custom message not part of WooCommerce',
           //Boolean that determines the display of the description
           'desc_tip' => true,
           //Standard html input placeholder
           'placeholder' => 'Type a message',
        );
        woocommerce_wp_text_input($field);
    }
    
    add_action('woocommerce_process_product_meta', 'save_my_custom_fields');
    
    function save_my_custom_fields($post_id) {
        update_post_meta(
            $post_id,
            'my_custom_message',
            esc_attr($POST['my_custom_message'])
        );
    }
    

    请尝试使用上面的代码并将 id 字段替换为您所需的参数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 2018-09-14
      • 2017-12-23
      • 2016-09-07
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多