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