Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucasstark/818eb74909a1d5be17cbb159c6dbb262 to your computer and use it in GitHub Desktop.
Save lucasstark/818eb74909a1d5be17cbb159c6dbb262 to your computer and use it in GitHub Desktop.
Custom export fields for WooCommerce Gravity Forms Product Addons
add_filter( 'gform_export_fields', 'custom_add_wc_order_fields', 10, 1 );
add_filter( 'gform_export_field_value', 'custom_export_wc_order_fields', 10, 4 );
function custom_add_wc_order_fields( $form ) {
array_push( $form['fields'], array(
'id' => 'woocommerce_billing_address_1',
'label' => __( 'WooCommerce Billing Address 1', 'wc_gf_addons' )
) );
array_push( $form['fields'], array(
'id' => 'woocommerce_billing_address_2',
'label' => __( 'WooCommerce Billing Address 2', 'wc_gf_addons' )
) );
//Add any additional fields you need included in the export.
}
function custom_export_wc_order_fields( $value, $form_id, $field_id, $entry ) {
switch ( $field_id ) {
case 'woocommerce_billing_address_1' :
$order_id = gform_get_meta( $entry['id'], 'woocommerce_order_number' );
if ( $order_id ) {
$order = wc_get_order( $order_id );
if ( $order ) {
$value = $order->get_billing_address_1();
}
}
break;
case 'woocommerce_billing_address_2' :
$order_id = gform_get_meta( $entry['id'], 'woocommerce_order_number' );
if ( $order_id ) {
$order = wc_get_order( $order_id );
if ( $order ) {
$value = $order->get_billing_address_2();
}
}
break;
}
/*
Add any additional fields you need included in the export.
See https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html for details on what functions are available to retrieve order information.
*/
return $value;
}
@animalregistry
Copy link

Hi, I am new to this, and would appreciate as much help as I could get. where exactly do I add this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment