duanfengwang9157 2018-08-27 12:52
浏览 51
已采纳

如何导出到woocommerce中的CSV选定元字段而不是所有元数据

I have added two extra meta fields in my inventory tab in woocommerce.

I would like when I export my products, to be able to select these two meta fields or to have them automatically added in my exported csv file.

Is this possible?

The following is the part of creating my meta field

// Display Fields using WooCommerce Action Hook
add_action( 'woocommerce_product_options_inventory_product_data', 
'woocom_inventory_product_data_custom_field' );

// Hook to save the data value from the custom fields
add_action( 'woocommerce_process_product_meta', 
'woocom_save_inventory_proddata_custom_field' );

/** Hook callback function to save custom fields information */
function woocom_save_inventory_proddata_custom_field( $post_id ) {

// Save Text Field
$text_field = $_POST['_text_field'];
if( ! empty( $text_field ) ) {
 update_post_meta( $post_id, '_text_field', esc_attr( $text_field ) );
}

}

function woocom_inventory_product_data_custom_field() {
// Create a custom text field

// Text Field
woocommerce_wp_text_input( 
array( 
  'id' => '_text_field', 
  'label' => __( 'My Info', 'woocommerce' ), 
  'placeholder' => 'My Info',
  'desc_tip' => 'true',
  'description' => __( 'Input value.', 'woocommerce' ) 
  )
);
}
  • 写回答

1条回答 默认 最新

  • douliedai4838 2018-08-27 14:10
    关注

    yes you can based on the WooCommerce Product CSV Importer & Exporter Documentation you can use the following hooks:

    /**
     * Add the custom column to the exporter and the exporter column menu.
     *
     * @param array $columns
     * @return array $columns
     */
    function add_export_column( $columns ) {
    
        // column slug => column name
        $columns['custom_column'] = 'Custom Column';
    
        return $columns;
    }
    add_filter( 'woocommerce_product_export_column_names', 'add_export_column' );
    add_filter( 'woocommerce_product_export_product_default_columns', 'add_export_column' );
    
    /**
     * Provide the data to be exported for one item in the column.
     *
     * @param mixed $value (default: '')
     * @param WC_Product $product
     * @return mixed $value - Should be in a format that can be output into a text file (string, numeric, etc).
     */
    function add_export_data( $value, $product ) {
        $value = $product->get_meta( 'custom_column', true, 'edit' );
        return $value;
    }
    // Filter you want to hook into will be: 'woocommerce_product_export_product_column_{$column_slug}'.
    add_filter( 'woocommerce_product_export_product_column_custom_column', 'add_export_data', 10, 2 );
    

    Reference

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。