Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/21dc7e69eaf7e8d2c4c372290e00e6a4 to your computer and use it in GitHub Desktop.
Save cameronjonesweb/21dc7e69eaf7e8d2c4c372290e00e6a4 to your computer and use it in GitHub Desktop.
<?php
/**
* Add the custom column to the exporter and the exporter column menu.
*
* @link https://github.com/woocommerce/woocommerce/wiki/Product-CSV-Importer-&-Exporter#adding-custom-export-columns-developers
*
* @param array $columns.
* @return array $columns.
*/
function cameronjonesweb_add_export_columns( $columns ) {
// column slug => column name.
$columns['slug'] = 'Slug';
return $columns;
}
add_filter( 'woocommerce_product_export_column_names', 'cameronjonesweb_add_export_columns' );
add_filter( 'woocommerce_product_export_product_default_columns', 'cameronjonesweb_add_export_columns' );
/**
* Provide the data to be exported for one item in the column.
*
* @link https://github.com/woocommerce/woocommerce/wiki/Product-CSV-Importer-&-Exporter#adding-custom-export-columns-developers
*
* @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 cameronjonesweb_export_column_slug( $value, $product ) {
$value = get_post_field( 'post_name', $product->get_id() );
return $value;
}
// Filter you want to hook into will be: 'woocommerce_product_export_product_column_{$column_slug}'.
add_filter( 'woocommerce_product_export_product_column_slug', 'cameronjonesweb_export_column_slug', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment