简体   繁体   English

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

[英]How to export to a CSV selected meta fields in woocommerce and not all metas

I have added two extra meta fields in my inventory tab in woocommerce.我在 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.我希望在导出产品时能够选择这两个元字段或将它们自动添加到导出的 csv 文件中。

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' ) 
  )
);
}

yes you can based on the WooCommerce Product CSV Importer & Exporter Documentation you can use the following hooks:是的,您可以基于 WooCommerce 产品 CSV 导入和导出文档,您可以使用以下挂钩:

/**
 * 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 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM