Advertisement
kayart

Add Parent ID column to WooCommerce products export file

Jun 26th, 2025
707
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. <?php
  2. add_filter( 'woocommerce_product_export_column_names', 'add_parent_id_export_column' );
  3. add_filter( 'woocommerce_product_export_product_default_columns', 'add_parent_id_export_column' );
  4.  
  5. function add_parent_id_export_column( $columns ) {
  6.     $columns['parent_number'] = 'Parent ID';
  7.     return $columns;
  8. }
  9.  
  10. add_filter( 'woocommerce_product_export_product_column_parent_number', 'populate_parent_id_export_data', 10, 2 );
  11. function populate_parent_id_export_data( $value, $product ) {
  12.     if ( $product->is_type( 'variation' ) ) {
  13.         $value = $product->get_parent_id();
  14.     } else {
  15.         $value = '';
  16.     }
  17.     return $value;
  18. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement