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 cconversion/49706f3dfdfad100080c979a41de3bd9 to your computer and use it in GitHub Desktop.
Save cconversion/49706f3dfdfad100080c979a41de3bd9 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment