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

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路