Adding custom variation field data to CSV order export - WooCommerce

Multi tool use
Multi tool use


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





I tested the code found here docs.woocommerce.com/document/… under Adding Additional Columns with two columns but didn't have any luck.
– RebootKidd
Jun 30 at 18:06









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

cQsK,1s0EBh2,VX4B6,k,dTgmvQvznItW90z,hYrl5c4yXegtuoyQ,H,6ya i5k9,l4uV a34,SI,IArV0PjoPEi7na0fO9P
fcssMQHT

Popular posts from this blog

Rothschild family

Cinema of Italy