Adding custom variation field data to CSV order export – WooCommerce

I have been searching everywhere for an answer and just keep hitting road block after road block I have added custom variations fields in WooCommerce using http://www.remicorson.com/woocommerce-custom-fields-for-variations/ These fields save correctly when updating products.

I have installed WooCommerce Customer / Order CSV Export and have added a meta_field column placing the meta_key found in the code below.

Screenshot of the fields

However when I export the CSV file the fields are empty. Anyone have any experience with getting the custom variation field data to appear when exporting order data via CSV.

Listed below is the custom variation code being used. Any guidance would be greatly appreciated.

/**
* Create new fields for variations
*
*/
function variation_settings_fields( $loop, $variation_data, $variation ) {

// Text Field
woocommerce_wp_text_input( 
    array( 
        'id'          => 'source_code[' . $variation->ID . ']', 
        'label'       => __( 'Supplier', 'woocommerce' ), 
        'desc_tip'    => 'true',
        'value'       => get_post_meta( $variation->ID, 'source_code', true )
    )
);
woocommerce_wp_text_input( 
    array( 
        'id'          => 'source_prod_id[' . $variation->ID . ']', 
        'label'       => __( 'Supplier ID', 'woocommerce' ), 
        'desc_tip'    => 'true',
        'value'       => get_post_meta( $variation->ID, 'source_prod_id', true ),
        'custom_attributes' => array(
                        'step'  => 'any',
                        'min'   => '0'
                    ) 
    )
);
woocommerce_wp_text_input( 
    array( 
        'id'          => 'pkg_desc[' . $variation->ID . ']', 
        'label'       => __( 'Package Size', 'woocommerce' ), 
        'desc_tip'    => 'true',
        'value'       => get_post_meta( $variation->ID, 'pkg_desc', true ),
        'custom_attributes' => array(
                        'step'  => 'any',
                        'min'   => '0'
                    ) 
    )
);          
            woocommerce_wp_text_input( 
    array( 
        'id'          => 'cost[' . $variation->ID . ']', 
        'label'       => __( 'Cost', 'woocommerce' ), 
        'desc_tip'    => 'true',
        'value'       => get_post_meta( $variation->ID, 'cost', true ),
        'custom_attributes' => array(
                        'step'  => 'any',
                        'min'   => '0'
                    ) 
    )
);

}

// Add Variation Settings
add_action( ‘woocommerce_product_after_variable_attributes’, ‘variation_settings_fields’, 10, 3 );

/**
* Save new fields for variations
*
*/
function save_variation_settings_fields( $post_id ) {

// Text Field
$text_field = $_POST['source_code'][ $post_id ];
if( ! empty( $text_field ) ) {
    update_post_meta( $post_id, 'source_code', esc_attr( $text_field ) );
}
$number_field = $_POST['source_prod_id'][ $post_id ];
if( ! empty( $number_field ) ) {
    update_post_meta( $post_id, 'source_prod_id', esc_attr( $number_field ) );
}
$number_field = $_POST['pkg_desc'][ $post_id ];
if( ! empty( $number_field ) ) {
    update_post_meta( $post_id, 'pkg_desc', esc_attr( $number_field ) );
}
$number_field = $_POST['cost'][ $post_id ];
if( ! empty( $number_field ) ) {
    update_post_meta( $post_id, 'cost', esc_attr( $number_field ) );
}

}

// Save Variation Settings
add_action( ‘woocommerce_save_product_variation’, ‘save_variation_settings_fields’, 10, 2 );

// Add Variation Settings
add_action( ‘woocommerce_product_after_variable_attributes’, ‘variation_settings_fields’, 10, 3 );

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s